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:
