android - 在 Android 中获取应用程序启动时的所有远程通知
问题描述
我需要notifications
在应用程序启动时从 android 通知中心收集所有远程(在应用程序未运行时收到)。
我尝试过使用该NotificationManager.getActiveNotifications
方法,但这给出了StatusBarNotification
. 有一种方法getNotification()
可用,StatusBarNotification
但这也没有远程通知内容。
我试过这样的事情,
NotificationManager notificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
StatusBarNotification[] notifications = notificationManager.getActiveNotifications();
for (int i = 0; i < notifications.length ; i++) {
Notification notification = notifications[i].getNotification();
Log.d("Tag","Notification String = " + notification.toString());
}
输出:
Notification String = Notification(channel=fcm_fallback_notification_channel pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)
请帮我提出您的建议。
非常感谢!
解决方案
如果您想获取通知数据,请使用
Bundle bundle = notification.extras
这里的 bundle 将接收到的所有数据作为有效负载。因此,如果您想获得标题,请使用bundle.getString("android.title")
;
推荐阅读
- ios - React Native ScrollView 自动隐藏键盘在低级设备上滞后
- javascript - ES6 导入的执行顺序,在 HTML 和代码中
- lua - 尝试将中间单击按钮分配给 LUA 自动点击器脚本(Logitech G203 鼠标)
- node.js - 当我最终将我的网站发布到主机服务器时,我是否会更改 app.listen('port number') ?
- angular - Angular - 将可观察对象的值分配给另一个可观察对象的字段
- javascript - 在javascript函数中使用AlpineJS(3)魔法属性
- android - Windows 上的 Android 备份提取器
- swift - 如何为 TimeInterval 创建格式化程序以打印分钟、秒和毫秒
- xcode - 我注意到在 Xcode 13 中,有时在项目中包含可交付成果的“产品”组有时是不可见的。有什么解决办法吗?
- python - 将 2 列数据框转换为多级分层数据框