1

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?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

4 Answers4

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
0

setFullScreenIntent in NotificationCompat.Builder

REXWAN
  • 61
  • 1
  • 2