Heloo,我正在构建一个应用程序,我通过Firebase控制台使用推送通知.我想知道简单推送通知和云消息之间的区别是什么?来自云消息传递的消息是数据消息(具有密钥和值),通知只是没有密钥和值的文本吗?我是对的吗?
google-cloud-messaging firebase-cloud-messaging firebase-notifications
我在Android应用中使用Firebase作为我们的消息服务.我已经对Firebase进行了相当多的研究,我理解无论应用程序是在前台运行还是现在运行都会改变onMessageReceived方法中收到的数据类型.
我想要完成的是解析来自Remotemessage的传入数据,并根据自定义标记执行与它不同的操作.IE,如果数据映射包含一个名为"My_Custom_Tag"的字段,我想完全覆盖弹出的标准firebase消息并编写一个自定义消息.
问题是,当应用程序在后台运行时,我放入onMessageReceived的任何代码都不会被触发.当应用程序在前台运行时,它可以正常工作,但如果应用程序在后台,则无法检测/接收任何内容.
以下是一些示例代码:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String, String> aMap = remoteMessage.getData();
//Custom object here for easier parsing
PushNotificationsPojo pojo = this.convertResponseToPojo(aMap);
if(pojo == null){
passToFirebase(remoteMessage);
return;
}
if(pojo.getData().getCustomTag().equals(PushNotificationsPojo.ID_TAG_CHAT_MESSAGE)) {
createCustomNotification1(pojo);
} else if (pojo.getData().getCustomTag().equals(PushNotificationsPojo.ID_TAG_SOME_OTHER_MESSAGE)){
createCustomNotification2(pojo);
} else if (pojo.getData().getCustomTag().equals(PushNotificationsPojo.ID_TAG_STUFF_AND_WHATNOT)) {
createCustomNotification3(pojo);
} else {
passToFirebase(remoteMessage);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何编辑MyFirebaseMessagingService以便我可以检查传入的数据,确定标记信息,并决定将其传递给firebase,以便它可以使用标准处理或不将其传递给firebase并编写我的我的应用程序在后台运行时,我自己的自定义显示通知?
谢谢大家!