轻击捆绑的通知不会触发PendingIntent [英] Tapping on a bundled notification doesn't trigger the PendingIntent
问题描述
因此,在牛轧糖中,来自同一应用的多个通知会自动捆绑到一个组中.我在通知中设置了一个PendingIntent,其中包含一些其他内容,如果轻按了特定的通知,它将启动特定的活动(深链接).
So in Nougat multiple notifications from the same app get automatically bundled into a group. I'm setting a PendingIntent with some extras on my notifications and if a specific notification is tapped, it launches a specific activity (deep linking).
但是,如果我点击通知包(即不扩展组),则我的应用程序就像是从启动器中启动一样启动的-即它的意图是空的,没有任何额外的功能(它不会通过提供的程序启动PendingIntent).
However, if I tap on the notification bundle (i.e. without expanding the group) my app is simply launched as if it was from the launcher - i.e. its intent is empty, there are no extras (it is not launched via the provided PendingIntent).
当用户点击通知包时,如何指定使用意图?
How can I specify an intent to use when user taps on a notification bundle?
推荐答案
我遇到了同样的问题,经过一番调查,似乎您无法设置要在Android决定自动对通知进行分组时使用的PendingIntent.
I faced the same issue and after some investigation, it seems you cannot set a PendingIntent to be used when Android decides to automatically group the notifications.
该实现位于AOSP源代码中的NotificationManagerService.maybeAddAutobundleSummary()处.在这种情况下,系统始终会生成一个PendingIntent来启动启动程序活动.
The implementation is at NotificationManagerService.maybeAddAutobundleSummary() in AOSP sources. In this situation the system always generates a PendingIntent to just launch the launcher activity.
What you could do manage the grouping and summary notifications yourself, such as described here: http://blog.danlew.net/2017/02/07/correctly-handling-bundled-android-notifications/
另一种选择是在启动应用程序时使用NotificationManager.getActiveNotifications()遍历活动的通知,然后决定要执行的操作(例如,处理找到的未决深层链接).
Another option would be to iterate through active notifications using NotificationManager.getActiveNotifications() when the app is launched and then decide what to do (e.g. handle a pending deep link if found).
这篇关于轻击捆绑的通知不会触发PendingIntent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!