每当我尝试更新通知或Intent时,都会创建一个我不想要的新通知。我认为问题在于,每当我尝试更新时,都没有识别出意图。代码链接如下:
https://gist.github.com/Kerron-Hutton/03799ac497128919225bbbd4efaffa25
答案 0 :(得分:2)
要更新PendingIntent
,您应该使用之前用过的REQUEST_CODE
来创建它。
PendingIntent pIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
要取消/删除现有PendingIntent
,您可以使用PendingIntent.cancel()
方法。
PendingIntent.getBroadcast(context, REQUEST_CODE, intent,
PendingIntent.FLAG_UPDATE_CURRENT).cancel();
要更新Notification
,您可以对要更新的NotificationManager.notify()
使用NOTIFICATION_ID
方法。
NotificationManager notificationManager= (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notification);
通知
id
在您的应用中应该是唯一的。如果一个 您的个人已发布具有相同id
的通知 申请并没有被取消,它将被取代 更新的信息。
要取消/删除现有Notification
,请将NotificationManager.Cancel()方法与要取消的NOTIFICATION_ID
一起使用。
notificationManager.cancel(NOTIFICATION_ID);
希望这会有所帮助〜