Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle Android FCM Messages when application is in Background with data payload? [duplicate]

Android push notification using FCM is unable to handle when application in background. Default message is displayed in notification tray.

Can Anyone help me how to handle the messages when application in background.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

}

This method is not called when application is in background. Any help will be great help for me.

like image 303
Raghul Sugathan Avatar asked Oct 18 '22 16:10

Raghul Sugathan


1 Answers

The onMessageReceived() will be always called if you receive the payload as "data" always from server.

Example : Payload from server should be like following :

{
 "data":{
 "id": 1,
 "missedRequests": 5
 "addAnyDataHere": 123
 },
 "to":"fhiT7evmZk8:APA91bFJq7Tkly4BtLRXdYvqHno2vHCRkzpJT8QZy0TlIGs......"
}

for more about this issue. Please refer following URL : Firebase onMessageReceived not called when app in background

like image 170
Ankit Mehta Avatar answered Oct 21 '22 01:10

Ankit Mehta