英文:
Open composable screen from notification using deeplink Android 13
问题
Android 13 设备
我试图从通知的深链接中打开一个可组合的屏幕。然而,浏览器应用程序一直打开,而不是应用程序,然后导航到正确的屏幕。
我有以下的可组合屏幕,在其中我指定了深链接。
composable(
route = "event_screen?id={id}&menuActionType={menuActionType}",
arguments = listOf(navArgument("id") {
type = NavType.StringType
nullable = true
defaultValue = null
}, navArgument("menuActionType") {
type = NavType.StringType
defaultValue = AgendaMenuActionType.OPEN.name
}),
deepLinks = listOf(navDeepLink {
this.uriPattern = "https://androidbox.me/event_screen/{id}"
action = Intent.ACTION_VIEW
})
)
在我的 AlarmReceiver
中,我正在创建要在通知中使用的待定意图。通知正常触发,但当我点击它时,它会打开浏览器应用程序。
val agendaIntent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://androidbox.me/event_screen/597ef216-2ec6-435b-9a48-cfcf0e3caa46"))
val pendingIntent = TaskStackBuilder.create(context).run {
this.addNextIntentWithParentStack(agendaIntent)
this.getPendingIntent(agendaId.hashCode(), PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_CANCEL_CURRENT)
}
val notification = NotificationCompat.Builder(context, channelId)
.setContentTitle(title)
.setContentText(description)
.setSmallIcon(R.drawable.bell)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build()
notificationManager.notify(agendaId.hashCode(), notification)
在我的清单中,我已经指定了如下:
<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:host="androidbox.me"
android:scheme="https">
</data>
</intent-filter>
当我点击通知时,它会打开浏览器。
使用以下方式进行测试:
./adb shell am start -W -a android.intent.action.VIEW -d https://androidbox.me/event_screen/597ef216-2ec6-435b-9a48-cfcf0e3caa46
Starting: Intent { act=android.intent.action.VIEW dat=https://androidbox.me/... }
Status: ok
LaunchState: WARM
Activity: com.android.chrome/org.chromium.chrome.browser.ChromeTabbedActivity
TotalTime: 140
WaitTime: 147
Complete
英文:
Android 13 Device
I am trying to open a composable screen from using a deeplink from a notification. However, the browser app keeps opening instead of the app and then navigating to the correct screen.
I have the following composable screen where I am specifying the deeplinks.
composable(
route = "event_screen?id={id}&menuActionType={menuActionType}",
arguments = listOf(navArgument("id") {
type = NavType.StringType
nullable = true
defaultValue = null
}, navArgument("menuActionType") {
type = NavType.StringType
defaultValue = AgendaMenuActionType.OPEN.name
}),
deepLinks = listOf(navDeepLink {
this.uriPattern = "https://androidbox.me/event_screen/{id}"
action = Intent.ACTION_VIEW
})
)
In my AlarmReceiver I am creating the pending Intent to be used in the notification. The notification triggers ok, but when I tap on it will open the browser app.
val agendaIntent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://androidbox.me/event_screen/597ef216-2ec6-435b-9a48-cfcf0e3caa46"))
val pendingIntent = TaskStackBuilder.create(context).run {
this.addNextIntentWithParentStack(agendaIntent)
this.getPendingIntent(agendaId.hashCode(), PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_CANCEL_CURRENT)
}
val notification = NotificationCompat.Builder(context, channelId)
.setContentTitle(title)
.setContentText(description)
.setSmallIcon(R.drawable.bell)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build()
notificationManager.notify(agendaId.hashCode(), notification)
And in my manifect I have specified like this:
<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:host="androidbox.me"
android:scheme="https">
</data>
</intent-filter>
What happens when I tap the notification it opens the browser.
Testing with the following
./adb shell am start -W -a android.intent.action.VIEW -d https://androidbox.me/event_screen/597ef216-2ec6-435b-9a48-cfcf0e3caa46
Starting: Intent { act=android.intent.action.VIEW dat=https://androidbox.me/... }
Status: ok
LaunchState: WARM
Activity: com.android.chrome/org.chromium.chrome.browser.ChromeTabbedActivity
TotalTime: 140
WaitTime: 147
Complete
答案1
得分: 0
答案是在清单文件中添加以下内容,因为这是一个深度链接而不是应用链接:
<intent-filter android:autoVerify="true">
<data
android:host="androidbox.me"
android:scheme="busbyapp">
</data>
</intent-filter>
英文:
The answer was to have the following in the manifest as this is a deeplink not a applink
<intent-filter android:autoVerify="true">
<data
android:host="androidbox.me"
android:scheme="busbyapp">
</data>
</intent-filter>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论