Android Heads-up notification appears for a few seconds then disappears from the home screen and stays in the status bar and Notification Drawer. Is there any way to show notification pop up on the home screen until the user interacts?
Asked
Active
Viewed 1,432 times
4 Answers
0
You require to create new Activity for that which will open when notification received. On received notification you need set payload in data as key-pair values because otherwise it will be handle By Android OS.
This will help- Android Activity as a dialog
How to handle notification when app in background in Firebase

Sameer Z.
- 3,265
- 9
- 48
- 72
0
If you don't mind turning your notification into a snackbar, you can show one that doesn't go away till user interacts with it:
public void showSnakbarIndef(final View rootView, String message, String actionMessage) {
Snackbar.make(rootView, message, Snackbar.LENGTH_INDEFINITE)
.setAction(actionMessage, new View.OnClickListener() {
@Override
public void onClick(View v) {
//exit or other action according to notification
}
})
.show();
}

Nikos Hidalgo
- 3,666
- 9
- 25
- 39
0
Use setOngoing(true)
and setAutoCancel(true)
in Notification.Builder
like so:
notification = new Notification.Builder(getApplicationContext())
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true)
.setAutoCancel(true)
.setContentText(contentText)
.setContentIntent(contentIntent)

Squti
- 4,171
- 3
- 10
- 21
-
This way the user won't be able to dismiss the notification at all unless they mute the channel altogether. – Nikos Hidalgo Oct 07 '19 at 14:33
-
Edited. Thank you @NikosHidalgo – Squti Oct 08 '19 at 06:48