FCM notification priority is being ignored for Android

Viewed 291

I'm testing priority for fcm notifications for android with below request. And tested the priorities with "normal" & "high".

curl --location --request POST 'https://fcm.googleapis.com/fcm/send' \
--header 'Authorization: key=##############################' \
--header 'Content-Type: application/json' \
--data-raw '{
"to":"##########################",
 "notification" : {
  "sound" : "default",
  "body" :  "high priority test",
  "title" : "high priority test",
  "content_available" : true,
  "priority" : "high",
  "time_to_live":4
 }
}'

Below is the code snippet I used to check the push notification priority in the android app. The issue is always getting the same priority even though I'm changing the priorities as "normal" & "high".

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    String channelId = "Default";
    NotificationCompat.Builder builder = new  NotificationCompat.Builder(this, channelId)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(remoteMessage.getNotification().getTitle())
            .setContentText(remoteMessage.getNotification().getBody()
                    +" original priority-" + remoteMessage.getOriginalPriority()
                    +" delivered priority-" + remoteMessage.getPriority()
            )
            .setAutoCancel(true).setContentIntent(pendingIntent);;
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
        manager.createNotificationChannel(channel);
    }
    manager.notify(0, builder.build());
}
1 Answers

I figured out the answer and the issue was with the place I was putting the "priority" parameter. It should be outside the notification object.

curl --location --request POST 'https://fcm.googleapis.com/fcm/send' \
--header 'Authorization: key=##############' \
--header 'Content-Type: application/json' \
--data-raw '{
"to":"##############################",
 "notification" : {
  "sound" : "default",
  "body" :  "high priority test11",
  "title" : "high priority test11",
  "content_available" : true,
  "time_to_live":4
 },
   "priority" : "high"
}'
Related