我想在用戶點擊通知時自動取消通知。以下代碼適用於除Android棒棒糖設備以外的所有設備。在棒棒糖設備中,通知只在用戶滑動時才進行。通知自動取消不適用於Android棒棒糖
@SuppressWarnings( 「棄用」) 公共無效sendNotification時(INT ID){
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Test")
.setContentText("Jump to next screen")
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true);
mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE;
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, NextActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,
resultIntent, 0);
//PendingIntent.FLAG_UPDATE_CURRENT
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// id, if there is a need to update the notification later on.
mNotificationManager.notify(id, mBuilder.build());
Log.v(TAG, "Notification ID value " + id);
//mNotificationManager.cancel(id);
}
缺什麼在此代碼?
即使我看到這個問題的特殊情況。你能找到解決辦法嗎?我看到的是,它被刪除,並且在通知中心發生任何刷新。 – Ayyappa 2015-03-20 16:45:21
正在關注。我也被卡住了。看了這麼多,但沒有解決這個問題呢。我目前正在運行計時器,並在計時器耗盡後取消所有通知。 – LokiDroid 2015-03-26 07:10:43