android - 来自 JetpackNavigation 库中通知的隐式深层链接

标签 android kotlin android-notifications deep-linking android-jetpack-navigation

我正在尝试在我的应用程序中实现隐式深层链接处理,但以下代码不起作用,并且我的单个 Activity 中的 onNewIntent 没有调用,但导航图中的 startDestination 始终处于打开状态。

在我的导航图中,我有以下 fragment 的深层链接

 <deepLink
        android:id="@+id/deepLink"
        app:uri="people/{uuid}" />

然后我添加了导航。图表到 Activity 标签之间的 list 文件
<nav-graph android:value="@navigation/app_graph" />

在我将 onNewIntent 实现放到 MainActivity 之后,它看起来像
 override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    findNavController(R.id.fragmentContainer).handleDeepLink(intent)
}

创建待处理 Intent 的过程如下:
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
)

最后是对话框创建
val notification = NotificationCompat.Builder(context, CHANNEL_ID)
        // not important
        .setContentIntent(pendingIntent)
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .build()

NotificationManagerCompat
    .from(context)
    .notify(Random.nextInt(), notification)

最佳答案

我认为首先你的方案是错误的,应该是 <scheme_name>://people/{uuid}

关于android - 来自 JetpackNavigation 库中通知的隐式深层链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61545670/

相关文章:

Kotlin中抽象容器工具的泛型输入/输出?

android - 如何在单元测试中使用 android 依赖项?

Android - 显示动画状态栏图标

java - Android:Notification.DEFAULT_VIBRATE 是否需要振动许可?

java - Android keystore 已损坏

android - 如何将微调器中的第一个值(默认值)设置为空

java - 不安全的密码加密模式,如何解决?

android - 使用 gradle 从存储库下载 apk

Kotlin 高阶函数组合

java - 当应用程序被系统杀死时如何删除通知?