1
在我的應用程序我創建3個通知(ID爲0,1,2)取決於一些數據。刪除所有通知點擊
我爲了讓系統將取消它在用戶點擊的通知使用
setCancel(true);
。 我想在其中一個用戶點擊所有通知(id 0,1,2)。 這可能嗎?
這是我講的通知創建代碼:
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, ActivityMain.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder builder = new Notification.Builder(context);
Notification notification = null;
builder.setContentTitle(title)
.setContentIntent(contentIntent);
notification = new Notification.BigTextStyle(builder).bigText(mex).build();
notificationManager.notify(id, notification);
是的,我已經看到了cancellAll方法,但我不知道如何在通知點擊時使用它。 謝謝。 – helloimyourmind
只需在通知中添加一個PendingIntent,一旦它被點擊,就會調用我告訴你的方法,或者如果你更願意取消一個通知調用'cancel(int id)'。在通知中添加一個操作:http://developer.android.com/training/notify-user/build-notification.html#action – GoRoS
我剛剛編輯了我的第一篇文章,添加了我用於創建通知。 我已經在使用一個意圖,我怎樣才能更新我的代碼,以便做你的建議? 謝謝。 – helloimyourmind