3

I have implemented FCM. The messages are receiving in Android N and lower devices.


dependency

implementation "com.google.firebase:firebase-messaging:17.1.0"

I have tried sending messages from firebase console. It showing in Android N but not in Android O.

I have tried sending data notification from the server. Didn't got any call on onMessageReceived() in Android O.


Added channel while showing notification

 val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

    // Since android Oreo notification channel is needed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val channel = NotificationChannel(channelId,
                "CRW notification channel",
                NotificationManager.IMPORTANCE_HIGH)
        notificationManager.createNotificationChannel(channel)
    }

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build())

I have checked this in Samsung S2 and One plus 6.

Do I need to do anything extra for Android O other than setting notification channel on showing the notification?

KENdi
  • 7,205
  • 2
  • 14
  • 26
Suneesh Ambatt
  • 805
  • 7
  • 22

2 Answers2

1

Did you set your FCM to high-priority.

Add this to your message body:

{
  ...
  "priority":"high"
  ...
}

High priority. FCM attempts to deliver high priority messages immediately, allowing the FCM service to wake a sleeping device when necessary and to run some limited processing (including very limited network access). 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.

Ref: https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message

HedeH
  • 2,571
  • 13
  • 21
  • Hi, i have a question here for similar problem, would be great if you can contribute https://stackoverflow.com/questions/51571235/cloud-function-fcm-send-error. Thanks – Prashant Jain Jul 29 '18 at 00:15
-1

Check this on server side the push message is sent as Data Payload or Notification For android version greater than M it requires to send notification in Data Payload By passing send Data (on server side). Also works when app is running in background.

  • The notification sent as Data payload. This is working as expected (both background and foreground) in Android L, M, and N. – Suneesh Ambatt Jul 25 '18 at 06:52
  • Check if this issue only the case in background – LadyEinstien Jul 25 '18 at 06:59
  • I suggest you to send both notification and data payload { "message":{ "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "notification":{ "title":"Portugal vs. Denmark", "body":"great match!" }, "data" : { "Nick" : "Mario", "Room" : "PortugalVSDenmark" } } } – LadyEinstien Jul 25 '18 at 07:01