FCM android块被忽略

时间:2019-05-21 05:43:16

标签: android firebase push-notification firebase-cloud-messaging apn

这是我的有效载荷。当我发送邮件时,我可以接收通知,但是 click_action 被忽略,它启动了启动器活动。但是,当我将“ click_action” 放在通知块中时,它正在工作。为什么 android阻止会被忽略?

{
"to": "my tocken",
"data": {
    "url": "dfhdfh",
    "action": "fhdfg",

},
"notification": {
    "title": "dfgsdfg",
    "body": "dfgdg"
},
"android": {
    "notification": {
        "click_action": "NOTIFICATION_ACTIVITY"
    }
}

}

2 个答案:

答案 0 :(得分:0)

firebase推送通知中有三种消息

  • 通知消息
  • 数据消息
  • 同时具有通知和数据有效负载的消息

并且在android端,这些类型的访问级别彼此有点不同,因此您需要了解在后端和android端都实现推送通知之前

通过阅读此博客https://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

,您可以更好地理解

答案 1 :(得分:0)

我认为您应该只发送数据消息,然后在onMessageReceived的{​​{1}}中,您可以生成自定义通知并从FirebaseMessagingService对象中检索数据。

RemoteMessage

在数据对象下,您可以具有多个用于通知的键值对以及您要执行的所有其他操作。

也将public class CloudMessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage){ //Extract data from remote message //trigger notification } } 声明为CloudMessagingService中的服务AndroidManifest.xml

intent-filter