我希望在用户点击通知后,通知能够关闭。我看到很多人都建议使用标志位,但是因为我正在使用NotificationCompat.Builder类而不是Notification类,所以我无法找到标志位。有人知道如何让通知自动移除吗?
这是我设置通知时的代码:
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());
getNotifications
已弃用,请使用mBuilder.build().flags |= Notification.FLAG_AUTO_CANCEL;
代替。该方法可以使通知自动取消。 - blueware