我试图在点击通知时取消通知,这在5.0以下工作得非常好。但不知何故,同样的通知在Android 5.0中不是autoCancel
以下是我以前使用的cancelNotification
(工作顺利< 5.0)
PendingIntent resultPendingIntent = PendingIntent.getActivity(ctx,
uniqueID, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_mobcast_notification)
.setContentTitle(message)
.setContentText(title)
.addAction(android.R.drawable.ic_menu_gallery, title,
resultPendingIntent);
mBuilder.setDefaults(-1);
mBuilder.setOnlyAlertOnce(true);
mBuilder.setAutoCancel(true);
mBuilder.setContentIntent(resultPendingIntent);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Notification notification = new NotificationCompat.BigPictureStyle(
mBuilder).bigPicture(
BitmapFactory.decodeFile(mImagePath, options)).build();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(434, notification);
尝试: -
尝试取消pendingIntent
导致的通知。但Notification Bar(5.0)
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancelAll();
我错过了为5.0设置的Extra Flag
有什么可以通过点击它来autoCancel
通知
答案 0 :(得分:0)
我使用了以下代码,它完美无缺,您可以尝试:
public void showNotification(View view) {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle("Message")
.setContentText("New Message")
.setTicker("Alert New Message")
.setSmallIcon(R.drawable.ic_launcher);
Intent moreInfoIntent = new Intent(this, MoreInfoNotification.class);
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this);
taskStackBuilder.addParentStack(MoreInfoNotification.class);
taskStackBuilder.addNextIntent(moreInfoIntent);
PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setAutoCancel(true);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(notifId, notificationBuilder.build());
isNotificActive = true;
}