0

I can see that

public void onMessageReceived(RemoteMessage remoteMessage)

is called when receiving push (when app is in background)

But it is not displaying any UI for the push notification.

I want something like the following

enter image description here

I think I've seen more than dozen SO questions, most notably the following one, but like I mentioned onMessageReceived is already getting called, just UI is not displaying.

How to handle notification when app in background in Firebase

My code for displaying ui for push is the following, do I need to do extra other than this?

   Notification notification = notificationBuilder.build();
   notification.flags |= Notification.FLAG_AUTO_CANCEL;

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

   JSONObject push = notificationArgsObj.optJSONObject("push");
   if(push != null) {
     String sound = push.optString("sound");
     if(sound.equals("default")) {
       notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
     }
   }

   notificationManager.notify(destination_id, notification);
AL.
  • 36,815
  • 10
  • 142
  • 281
eugene
  • 39,839
  • 68
  • 255
  • 489
  • You built a notification (`notificationBuilder.build();`) but didn't really set any other data about it (like the content title/text). Try adding them first and see if it shows up. – AL. Dec 07 '18 at 11:29

1 Answers1

-1

Have you tried to setChannelId?

Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel. For each channel, you can set the visual and auditory behavior that is applied to all notifications in that channel. Then, users can change these settings and decide which notification channels from your app should be intrusive or visible at all.

Caution: If you target Android 8.0 (API level 26) and post a notification without specifying a notification channel, the notification does not appear and the system logs an error.

https://developer.android.com/training/notify-user/channels

Reedy Creeker
  • 139
  • 1
  • 4