Skip to content

Commit

Permalink
Handle URI scheme "ani://subjects/{id}" on Android, close #1202
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Nov 15, 2024
1 parent 9d8162b commit 79cf793
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
15 changes: 13 additions & 2 deletions app/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
<!-- Include one or more domains that should be verified. -->
<data android:host="bangumi-oauth-callback" />
</intent-filter>

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="ani" />

<data android:host="subjects" />
</intent-filter>
</activity>

<provider
Expand All @@ -72,8 +83,8 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<service

<service
android:name="me.him188.ani.app.domain.torrent.service.AniTorrentService"
android:description="@string/service_torrent_engine_description"
android:enabled="true"
Expand Down
18 changes: 15 additions & 3 deletions app/android/src/main/kotlin/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import me.him188.ani.app.ui.foundation.widgets.LocalToaster
import me.him188.ani.app.ui.foundation.widgets.Toaster
import me.him188.ani.app.ui.main.AniApp
import me.him188.ani.app.ui.main.AniAppContent
import me.him188.ani.utils.logging.error
import me.him188.ani.utils.logging.info
import me.him188.ani.utils.logging.logger
import org.koin.android.ext.android.inject
Expand All @@ -60,13 +61,24 @@ class MainActivity : AniComponentActivity() {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)

KoinPlatformTools.defaultContext().getOrNull()?.get<NotifManager>()?.let {
val code = intent.getIntExtra(EXTRA_REQUEST_CODE, -1)
if (code != -1) {
val code = intent.getIntExtra(EXTRA_REQUEST_CODE, -1)
if (code != -1) {
KoinPlatformTools.defaultContext().getOrNull()?.get<NotifManager>()?.let {
logger.info { "onNewIntent requestCode: $code" }
AndroidNotifManager.handleIntent(code)
}
}

val data = intent.data ?: return
if (data.scheme != "ani") return
if (data.pathSegments.getOrNull(0) == "subjects") {
val id = data.pathSegments.getOrNull(1)?.toIntOrNull() ?: return
try {
aniNavigator.navigateSubjectDetails(id)
} catch (e: Exception) {
logger.error(e) { "Failed to navigate to subject details" }
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down

0 comments on commit 79cf793

Please sign in to comment.