How to handle Android FCM Messages when applicatio

2019-04-29 23:52发布

问题:

This question already has an answer here:

  • How to handle notification when app in background in Firebase 22 answers

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.

回答1:

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