gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:04:07 24 4
gpt4 key购买 nike

我正在尝试在我的应用程序中实现隐式深层链接处理,但以下代码不起作用,并且我的单个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com