您可以在通知中添加标记:
http://developer.android.com/reference/android/app/Notification.html#FLAG_AUTO_CANCEL
这将在点击时解除它。
这是通知:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_calendar) .setContentTitle("My Firebase Push notification") .setContentText(message) .setAutoCancel(true) .setSound(soundUri) .setContentIntent(pendingIntent);
点击取消后面的关键是:
.setAutoCancel(true)
我希望它能解决这个问题。
试试这个....
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); .......... NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( this).setSmallIcon(R.drawable.push_notify_icon) .setContentTitle("New Question!") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setAutoCancel(true).setContentText("" + QuestionData.getAuthor().getUserName() + ": " + QuestionData.getQuestion() + ""); mBuilder.setContentIntent(contentIntent); .............. mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(0, mBuilder.build());
简单,简单地称之为:
mBuilder.setAutoCancel(true);
此外,虽然它并不是真的有必要,但如果你真的想使用它 FLAG_AUTO_CANCEL ,在打电话之前打电话给你 mNotificationManager.notify :
FLAG_AUTO_CANCEL
mNotificationManager.notify
mBuilder.build().flags |= Notification.FLAG_AUTO_CANCEL;