当应用程序处于具有数据有效负载的后台时,如何处理Android FCM消息? [英] How to handle Android FCM Messages when application is in Background with data payload?

查看:106
本文介绍了当应用程序处于具有数据有效负载的后台时,如何处理Android FCM消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用FCM的Android推送通知无法在后台运行应用程序时处理.默认消息显示在通知托盘中.

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.

推荐答案

如果始终从服务器接收有效载荷作为数据",则将始终调用onMessageReceived().

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......"
}

有关此问题的更多信息.请参考以下URL:​​ Firebase onMessageReceived在后台运行时未调用

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

这篇关于当应用程序处于具有数据有效负载的后台时,如何处理Android FCM消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆