0

I have Implemented FCM Firebase Cloud Messaging in my application. I got notification and its data when app in forground mode.

Problem:

When my app is in background mode or killed at that time notification arrive but its genrate auto by FCM. So I have no control of arrived notification data(coustom data field of notification). onMessageReceived(RemoteMessage remoteMessage) method of MyFirebaseMessagingService class not call when app in background mode and notification arrive.

Please help to get notification control in both mode (Same like GCM)

Tim
  • 41,901
  • 18
  • 127
  • 145
Jatinkumar Patel
  • 1,094
  • 2
  • 17
  • 34

1 Answers1

5

Problem:

When my app is in background mode or killed at that time notification arrive but its genrate auto by FCM. So I have no control of arrived notification data(coustom data field of notification). onMessageReceived(RemoteMessage remoteMessage) method of MyFirebaseMessagingService class not call when app in background mode and notification arrive.

Please help to get notification control in both mode (Same like GCM)

You have no control over Notification if you are sending the notifications using Firebase Console. A notification send from Firebase Console is not delivered in onMessageReceived() method if the app is in background or killed.

Solution:

Send notifications using curl requests and don't send notification payload instead send data payload.

HTTP POST Request

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

Above Notification will be delivered in onMessageReceived() method whether your app is in background or foreground or killed.

Try with Advanced REST Client, image for help:

enter image description here

Hisham Muneer
  • 8,558
  • 10
  • 54
  • 79
  • 2
    why are you posting this answer, if you just basically agreed that it was a duplicate – Tim Jul 12 '16 at 07:30