与 pin screen 和 firebase 推送通知的深度链接

时间:2021-05-11 15:51:07

标签: android push-notification deep-linking android-deep-link

我的目标:我想向用户发送推送通知。当用户点击该通知时,用户应导航到名为 HitoryDe​​tailsFragment 的特定片段。

我所做的:我实现了 FirebaseInstanceIdService 和 FirebaseMessagingService,并且能够捕获从后端服务器发送的 Firebase 消息。我通过“隐式深层链接”实现了深层链接。我使用嵌套导航图实现了导航。与历史相关的屏幕放置在单独的导航图 graph_history.xml 中。

问题是什么:当应用程序打开时,一切正常。我点击通知 -> 我被重定向到 HistoryDe​​tailFragment,当我按下后退按钮时,它会返回到 HistoryListFragment。但是当应用程序关闭时(不在最近的应用程序托盘中),而不是 HistoryDe​​tailsFragment,SplashFragment 被打开,之后我被重定向到 HomeFragment(这是正确的,因为这就是流程应该如何工作)。但是,当应用程序关闭时,如何将用户重定向到 HistoryDe​​tails?此外,我应该显示一个 Pin 屏幕,用户应该在其中输入他的 pin,如果他之前没有,在显示 HistoryDe​​tailsFragment 之前。

我的代码如下。

private fun createPendingIntent(history: History?) = NavDeepLinkBuilder(this).run {
    setGraph(R.navigation.graph_main)
    history?.let {
        //todo when the app is not open (not in tray of recent apps), this destination does not work
        //this instead navigates to SplashFragment
        //which is correct, because we have not entered the pin, so we are not entitled to open the history detail screen
        //but how do I handle this case?
        setDestination(if (it.type.isNews) R.id.nav_history_news else R.id.nav_history_detail)
        setArguments(if (it.type.isNews) HistoryNewsFragmentArgs(it.link).toBundle() else HistoryDetailFragmentArgs(it.id).toBundle())
    }
    createPendingIntent()
}

主导航图: enter image description here

历史图表:

enter image description here

0 个答案:

没有答案
相关问题