【发布时间】:2010-05-14 06:28:05
【问题描述】:
根据我的情况,我在状态栏中显示Notification。到此为止,没关系。
现在我的应用程序的问题是当我回到应用程序时,状态栏中仍然显示Notification。
当我从应用程序返回时,我不想要 Notification。为此,请给我一些建议。
【问题讨论】:
标签: android android-notifications
根据我的情况,我在状态栏中显示Notification。到此为止,没关系。
现在我的应用程序的问题是当我回到应用程序时,状态栏中仍然显示Notification。
当我从应用程序返回时,我不想要 Notification。为此,请给我一些建议。
【问题讨论】:
标签: android android-notifications
我没有足够的代表来添加评论,所以 @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();
【讨论】:
您可以通过NotificationManagercancel() 您自己的Notifications。由您决定何时cancel() 以及何时显示。
【讨论】:
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();
}
}
【讨论】: