Я использую это, чтобы уведомить пользователя о текущем обслуживании в фоновом режиме.
nm = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "App";
CharSequence message = "Getting Latest Items...";
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
notif = new Notification(R.drawable.icon,
"Getting Latest Items...", System.currentTimeMillis());
notif.setLatestEventInfo(this, from, message, contentIntent);
notif.flags = Notification.FLAG_ONGOING_EVENT;
nm.notify(1, notif);
Теперь, когда обслуживание завершено, как мне заставить это исчезнуть?
2 ответа
Вызов cancel () в NotificationManager
Существуют разные способы отмены:
public void cancel (int id)
Since: API Level 1
Cancel a previously shown notification. If it's transient, the view will be hidden. If it's persistent, it will be removed from the status bar.
public void cancel (String tag, int id)
Since: API Level 5
Cancel a previously shown notification. If it's transient, the view will be hidden. If it's persistent, it will be removed from the status bar.
public void cancelAll ()
Since: API Level 1
Cancel all previously shown notifications. See cancel(int) for the detailed behavior.
Когда ваша служба останавливается, должна вызываться ее onDestroy (). Вы можете поместить там cancel (), о котором упоминала Вирен. Это должно стереть ваше уведомление, когда служба завершит свою работу.
Похожие вопросы
Новые вопросы
android
Android - это мобильная операционная система Google, используемая для программирования или разработки цифровых устройств (смартфоны, планшеты, автомобили, телевизоры, одежда, стекло, IoT). Для тем, связанных с Android, используйте специальные теги Android, такие как android-intent, android-activity, android-адаптер и т. Д. Для вопросов, не связанных с разработкой или программированием, но связанных с платформой Android, используйте эту ссылку: https: // android.stackexchange.com .