我希望通知将关闭后,用户点击它。我看到每个人都说要使用标志,但是我在任何地方都找不到标志,因为我使用的是NotificationCompat.Builder类,而不是通知类。有人知道如何让通知自己删除吗?
下面是我设置通知时的代码:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("New Question")
.setContentText("" + QuestionData.getAuthor().getUserName() + ": " + QuestionData.getQuestion() + "");
Intent openHomePageActivity = new Intent("com.example.ihelp.HOMEPAGEACTIVITY");
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntent(openHomePageActivity);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());发布于 2013-03-28 01:01:00
简单地说,就是这样:
mBuilder.setAutoCancel(true);此外,虽然这并不是真正必要的,但如果您真的想使用FLAG_AUTO_CANCEL,那么在调用mNotificationManager.notify之前调用它就可以了
mBuilder.build().flags |= Notification.FLAG_AUTO_CANCEL;发布于 2014-08-20 00:10:35
试试这个..。
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());发布于 2018-08-26 14:19:37
以下是通知:
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)我希望它能解决这个问题。
https://stackoverflow.com/questions/15120821
复制相似问题