android - 更新通知时记录“D/Notification:allPendingIntents”
问题描述
我在更新进度时更新通知,并且每次收到不在我的代码中的日志时:
D/Notification: allPendingIntents
通知创建代码:
mProgressNotifBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setPriority(Notification.PRIORITY_HIGH)
.setContentTitle(notifTitle)
.setAutoCancel(false)
.setProgress(MAX_PROGRESS, 0, true)
.setContentIntent(getPendingIntent());
setOfflineNotificationChannelId();
Notification notification = mProgressNotifBuilder.build();
startForeground(NOTIF_ID, notification);
mNotificationManager.notify(NOTIF_ID, notification);
更新通知代码:
private void updateNotificationProgress(int present) {
mProgressNotifBuilder.setProgress(MAX_PROGRESS, present, false);
mNotificationManager.notify(NOTIF_ID, mProgressNotifBuilder.build());
}
此日志是什么意思,我该如何解决?
解决方案
希望能帮到你,我最近一直遇到这个问题,我想你需要补充一下:
.setChannelId(NOTIFICATION_CHANNEL_ID)
在你的代码中。另请查看此链接: https ://developer.android.com/training/notify-user/channels 并观看视频。
所以你的代码应该是这样的;
mProgressNotifBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setPriority(Notification.PRIORITY_HIGH)
.setContentTitle(notifTitle)
.setAutoCancel(false)
.setChannelId(NOTIFICATION_CHANNEL_ID) // <---- add this
.setProgress(MAX_PROGRESS, 0, true)
.setContentIntent(getPendingIntent());
setOfflineNotificationChannelId();
Notification notification = mProgressNotifBuilder.build();
startForeground(NOTIF_ID, notification);
mNotificationManager.notify(NOTIF_ID, notification);
推荐阅读
- elasticsearch - 如何在 ELK 中进行实时警报
- vba - 使用 VBA 在 SAP GUI 中查找组件
- c++ - 从函数返回唯一的 void 指针
- reactjs - 带有 Reactjs Web 应用程序的 Google Amp
- java - 在不同的包中为同一类使用两个 CDI 生产者 (Intellij)
- android - 如何为 Oreo 8.0 以下的 Android 创建带有通知的前台服务?
- asp.net - 如何在 ASP.Net 中路由 Overidden Get 方法
- javascript - 是否可以在无头 chrome 中列出/杀死/...所有待处理的承诺/异步事件?
- android - 从网页获取 CSS 并将其加载到 android webview
- reactjs - 如何使用本机反应校准相机?