6
Ich möchte eine Benachrichtigung erstellen, ohne vorherige Benachrichtigungen aus meiner App zu löschen/löschen. Hier ist mein Code eine Benachrichtigung für die Erstellung von:Android: Nach dem Erstellen einer neuen Benachrichtigung wird der ältere ersetzt
private void notification(Context context, String title, String content) {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(title)
.setContentText(content);
Intent resultIntent = new Intent(context, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//Id allows you to update the notification later on.
mNotificationManager.notify(100, mBuilder.build());
}