Notifications unter Pie

S

Schneemann3

Ambitioniertes Mitglied
6
Ich hab das Problem, dass unter Oreo und Nougat immer eine Notification meiner App angezeigt wurde, unter Pie aber eine ganze Liste und für jede Notification ein neues Icon.
Ich will aber nur die letzte, aktuellste Meldung sehen.

Code:
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            String NOTIFICATION_CHANNEL_ID = "test";
            NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
                            .setSmallIcon(R.drawable.ic_stat_name)
                            .setContentTitle("Achtung!")
                            .setContentText(remoteMessage.getData().get("message"))
                            .setSound(alarmSound)
                            .setOnlyAlertOnce(true);

            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

            // Set the intent that will fire when the user taps the notification.
            mBuilder.setContentIntent(pendingIntent);
            int mNotificationId = 101;
            NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

            // Since android Oreo notification channel is needed.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                        "Test Channel",
                        NotificationManager.IMPORTANCE_DEFAULT);
                mNotifyMgr.createNotificationChannel(channel);
            }

            // mNotifyMgr.cancelAll();
            mNotifyMgr.cancel(0);
            mNotifyMgr.notify(0, mBuilder.build());

Mein Stand ist, dass eine Notification durch eine andere ersetzt wird, wenn die neue die gleiche ID (hier 101) hat.
Funktioniert aber irgendwie nicht mehr.
Auch cancel oder cancelAll hilft nicht.
 

Ähnliche Themen

B
Antworten
4
Aufrufe
487
bb321
B
S
Antworten
3
Aufrufe
636
swa00
swa00
S
Antworten
5
Aufrufe
885
swa00
swa00
Zurück
Oben Unten