【问题标题】:FCM android block is getting ignoredFCM android块被忽略
【发布时间】:2019-05-21 05:43:16
【问题描述】:

这是我的有效载荷。当我发送它时,我能够收到通知,但 click_action 被忽略并启动启动器活动。但是当我将 "click_action" 放在通知块中时,它正在工作。为什么 android 块 会被忽略?

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

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

}

【问题讨论】:

  • 有两种消息协议:LegacyHTTP v1。看起来您正在尝试使用两者中的元素。你有看起来像旧消息的东西,但旧协议没有“android”块。

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


【解决方案1】:

firebase 推送通知中有三种类型的消息

  • 通知消息
  • 数据消息
  • 带有通知和数据负载的消息

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

您可以通过阅读此博客https://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/获得更好的理解

【讨论】:

    【解决方案2】:

    我认为您应该只发送数据消息,然后在FirebaseMessagingServiceonMessageReceived 中,您可以生成自定义通知并从RemoteMessage 对象中检索数据。

    public class CloudMessagingService extends FirebaseMessagingService {    
        @Override
        public void onMessageReceived(RemoteMessage remoteMessage){
            //Extract data from remote message
            //trigger notification
        }
     }
    

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

    还将CloudMessagingService 声明为AndroidManifest.xml 中的服务,intent-filter

    <service android:name=".fcm.CloudMessagingService">
                <intent-filter>
                    <action android:name="com.google.firebase.MESSAGING_EVENT"/>
                </intent-filter>
            </service>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多