Yos*_*oof 115 eclipse notifications android
我想要在用户点击后关闭通知.我看到每个人都说使用标志,但我无法在任何地方找到标志,因为我使用的是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());
Run Code Online (Sandbox Code Playgroud)
ing*_*.am 311
简单,简单地称之为:
mBuilder.setAutoCancel(true);
Run Code Online (Sandbox Code Playgroud)
此外,虽然它并非真的有必要,但如果您真的想使用FLAG_AUTO_CANCEL,请在致电之前致电mNotificationManager.notify:
mBuilder.build().flags |= Notification.FLAG_AUTO_CANCEL;
Run Code Online (Sandbox Code Playgroud)
Sil*_*uti 18
试试这个....
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());
Run Code Online (Sandbox Code Playgroud)
这是通知:
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);
Run Code Online (Sandbox Code Playgroud)
取消点击的关键是:
.setAutoCancel(true)
Run Code Online (Sandbox Code Playgroud)
我希望它能解决问题。
您可以在通知中添加标记:
http://developer.android.com/reference/android/app/Notification.html#FLAG_AUTO_CANCEL
单击后将关闭它。
| 归档时间: |
|
| 查看次数: |
76174 次 |
| 最近记录: |