Wie entferne ich die Benachrichtigung aus der Statusleiste?
-
26-09-2019 - |
Frage
Ich zeige a Notification
in Statusleiste abhängig von meinem Zustand. Bis zu diesem ist es in Ordnung.
Jetzt ist das Problem in meiner Bewerbung, wenn ich zur Anwendung zurückkomme, immer noch die Notification
wird in der Statusleiste angezeigt.
Ich will das nicht Notification
Wenn ich aus der Anwendung zurückkomme. Geben Sie mir einige Vorschläge.
Lösung
Du kannst cancel()
dein eigenes Notifications
über die NotificationManager
. Es liegt an Ihnen, zu entscheiden, wann cancel()
es und wann man es zeigt.
Andere Tipps
Ich habe nicht genug Repräsentanten, um einen Kommentar hinzuzufügen, also @Commonware. . . Für zukünftige Leser wäre es hilfreicher, wenn Sie spezifischere Details geben, beispielsweise ihnen, dass sie eine verwenden sollen "Benachrichtigungs -ID" Wenn sie die Benachrichtigung erstellen und diese ID verwenden, um die Benachrichtigung zu stornieren. Wenn Sie eine Antwort geben, machen Sie sie vollständig oder geben Sie zumindest die vollständigen Details an. Diese Beiträge sind nicht nur für das OP bestimmt, sondern auch anderen, die auf diesen Beitrag stoßen. Wie so
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);
Dann, um es zu stornieren, rufen Sie an
notificationManager.cancel(NOTIFICATION_ID);
Oder Sie können anrufen
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();
}
}