我在更新进度的同时更新通知,每次获取不在我的代码中的日志时:
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());
}
此日志是什么意思,我该如何解决?
答案 0 :(得分:0)
希望我能为您提供帮助,我最近遇到了这个问题,我想您需要添加:
.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);