What I want is to make that while the app is open the notification does not close, the notification has a button to expand that is to close it.
To help me they have as an example the code of the notification:
Intent notificationIntent = new Intent(this, MainActivity.class); //<-- La clase que se abrira al hacer click en la notificacion
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
notificationIntent.putExtra("notificationID", notificationID);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
CharSequence ticker ="Exit";
CharSequence contentTitle = "App Open Mode";
CharSequence contentText = "App Notification Open Mode";
Notification noti = new NotificationCompat.Builder(this)
.setContentIntent(pendingIntent)
.setTicker(ticker)
.setContentTitle(contentTitle)
.setContentText(contentText)
.setSmallIcon(R.mipmap.ic_launcher)
.addAction(R.mipmap.ic_launcher, ticker, pendingIntent)
.build();
nm.notify(notificationID, noti);
I tried using this:
notif.flags = Notification.FLAG_ONGOING_EVENT;
But the app closes and does not work.