题
我正在展示一个 Notification
在状态栏中取决于我的状况。为此,还可以。
现在我的应用程序中的问题是我回到应用程序时,仍然是 Notification
显示在状态栏中。
我不要 Notification
当我从应用程序回来时。为此给我一些建议。
解决方案
你可以 cancel()
你自己 Notifications
通过 NotificationManager
. 。由您决定何时 cancel()
它以及何时显示。
其他提示
我没有足够的代表来添加评论,因此@commonware。 。 。如果您提供了更多具体细节,例如告诉他们使用 “通知ID” 当他们创建通知并使用该ID取消通知时。如果您给出答案,请完整或至少提供全部详细信息。这些帖子不仅是针对OP的,还可以帮助遇到此帖子的其他人。像这样
final NotificationManager notificationManager = (NotificationManager) getSystemService (NOTIFICATION_SERVICE);
final Notification notification = new Notification(R.drawable.icon,"A New Message!",System.currentTimeMillis());
notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(this, AndroidNotifications.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
notification.setLatestEventInfo(AndroidNotifications.this, title,message, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
然后取消您打电话
notificationManager.cancel(NOTIFICATION_ID);
或者你可以打电话
notificationManager.cancelAll();
notificationManager.cancelAll();
private void cancelNotificationInBar() {
NotificationCreator notification = new NotificationCreator(getApplicationContext());
notification.mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
if (notification.mNotificationManager != null) {
notification.mNotificationManager.cancelAll();
}
}
不隶属于 StackOverflow