gro*_*myk 10 android deep-linking android-notifications kotlin android-jetpack-navigation
我正在尝试在我的应用程序中实现隐式深层链接处理,但以下代码不起作用,并且我的单个活动中的 onNewIntent 没有调用,但导航图中的 startDestination 始终处于打开状态。
在我的导航图中,我有以下片段的深层链接
<deepLink
android:id="@+id/deepLink"
app:uri="people/{uuid}" />
Run Code Online (Sandbox Code Playgroud)
然后我添加了导航。图到活动标签之间的清单文件
<nav-graph android:value="@navigation/app_graph" />
Run Code Online (Sandbox Code Playgroud)
在我将 onNewIntent 实现放到 MainActivity 之后,它看起来像
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
findNavController(R.id.fragmentContainer).handleDeepLink(intent)
}
Run Code Online (Sandbox Code Playgroud)
创建待定意图的过程如下:
val intent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
data = Uri.parse("people/$uuid")
}
val pendingIntent = PendingIntent.getActivity(
context,
PENDING_INTENT_REQUEST_CODE,
intent,
0
)
Run Code Online (Sandbox Code Playgroud)
最后创建对话框
val notification = NotificationCompat.Builder(context, CHANNEL_ID)
// not important
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.build()
NotificationManagerCompat
.from(context)
.notify(Random.nextInt(), notification)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1072 次 |
| 最近记录: |