'Heads up push notification not doing the Pop up function

I am new to Android and I have been trying to show a Heads up action push notification just like whatsapp does.

This is my configuration for my notification:

NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, ADMIN_CHANNEL)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_foreground))
                        .setSmallIcon(R.drawable.m_icon)
                        .setContentTitle(remoteMessage.getNotification().getTitle())
                        .setTicker(remoteMessage.getNotification().getBody())
                        .setColor(ContextCompat.getColor(getApplicationContext(), R.color.mblue))
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(remoteMessage.getNotification().getBody()))
                        .setPriority(NotificationCompat.PRIORITY_HIGH)
                        .setContentIntent(likePendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0,notificationBuilder.build());

I have read in some post that the key to acomplish this is to set high priority to the notification but, It is still not working for me.



Solution 1:[1]

For Android Pie (9) on the emulator, I setup my channel with "IMPORTANCE_HIGH", and also set my builder priority to "PRIORITY_HIGH".

But, I still could not get heads-up notifications!

Finally, on the Android 9 emulator, I had to:

  1. swipe down the notifications drawer
  2. tap on "Manage Notifications"
  3. select my app
  4. select my channel
  5. select "Behavior"
  6. enable "Make sound and pop on screen".

Now it works.

Solution 2:[2]

The issue is that we have to add a new channel configuration whenever the OS is Oroe. So I had to validate if the OS is Oreo and then asign a channel to my notificationManager:

NotificationManager notificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
    setupChannels();
}

@RequiresApi(api = Build.VERSION_CODES.O)
private void setupChannels(){
    CharSequence adminChannelName ="Global channel";
    String adminChannelDescription = "Notifications sent from the app admin";
    NotificationChannel adminChannel;
    adminChannel = new NotificationChannel(ADMIN_CHANNEL_ID, adminChannelName, NotificationManager.IMPORTANCE_HIGH);
    adminChannel.setDescription(adminChannelDescription);
    adminChannel.enableLights(true);
    adminChannel.setImportance(NotificationManager.IMPORTANCE_HIGH);
    adminChannel.setLightColor(Color.RED);
    adminChannel.enableVibration(true);
    if (notificationManager != null) {
        notificationManager.createNotificationChannel(adminChannel);
    }

}

Solution 3:[3]

Just Add This Line In Your Notification Channel Builder:-

channel.setShowBadge(true)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BlueSpectrumz
Solution 2 Luis Aguilar
Solution 3 Pankaj Kumar