Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase notifications are not sending as high priority

When I send a notification to my Android device through the Firebase web interface, the notification doesn't peek down from the status bar. If I want to see the notification, I must swipe down. This occurs even when I have the priority set to High in the web interface. Why is this?

This is not an issue if the notification arrives when the app is open because I can set the priority myself in my FirebaseMessagingService class:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

  @Override public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    sendNotification("Message Body");

  }

  /**
   * Create and show a simple notification containing the received FCM message.
   *
   * @param messageBody FCM message body received.
   */
  private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, SubscribedActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
        PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_push_notification)
        .setContentTitle("FCM Message")
        .setContentText(messageBody)
        .setAutoCancel(true)
        .setSound(defaultSoundUri)
        .setPriority(NotificationCompat.PRIORITY_MAX)
        .setColor(ContextCompat.getColor(this, R.color.color_accent))
        .setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
  }
}
like image 570
Dick Lucas Avatar asked Jan 08 '17 00:01

Dick Lucas


1 Answers

When the app is open, you are handling your own notification and therefore you can control what it does. However, when the app is in background, the notification is handled by system tray and the only priority paramaters you can pass from the web console are high and normal. Passing the prority as high however will not work as intended if the users don't interact with your app. Documentation

High priority messages generally should result in user interaction with your app. If FCM detects a pattern in which they don't, your messages may be de-prioritized.

like image 51
Lucem Avatar answered Nov 13 '22 16:11

Lucem