【问题标题】:Huawei Push Kit API - Read data from payload of Notifications - onRemoteMessageReceived don't work华为推送工具包 API - 从通知的有效负载中读取数据 - onRemoteMessageReceived 不起作用
【发布时间】:2021-11-23 03:22:47
【问题描述】:

我想从此推送通知的有效负载中读取日期字段,但 api 似乎不起作用:(

我现在来自 hms 华为,我已经阅读了这个教程: HMS-Plugin-Guides-V1

除d点外所有部分都已完成,->覆盖错误。

当我发送通知并推送通知时。一切正常,我的应用程序将打开。但我无法阅读通知正文。

在日志中我看到通知服务启动 -> 获取令牌并立即杀死自己...我不明白问题出在哪里。

通知 JSON


{
    "validate_only": false,
    "message": {
        "notification": {
            "title": "Notifica simpatica",
            "body": "Io sono il body della notifica simpatica",
            "notify_icon": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png"
        },
        "data": "{'param1':'value1','param2':'value2'}",
        "android": {
            "collapse_key": -1,
            "urgency": "NORMAL",
            "category": "PLAY_VOICE",
            "ttl": "1448s",
            "fast_app_target": 1,
            "notification": {
                "click_action": {
                    "type": 1,
                    "intent": "intent://eccc_ecc"
                }
            }
        },
        "token":-xxxxx"
        ]
    }
}


我的应用代码:

   const App = () => {
    
      HmsPushEvent.onTokenReceived(result => {
        console.log('Push token', result.token);
      });
    
      HmsPushEvent.onRemoteMessageReceived(event => {
        console.log('Data message received');
        const RNRemoteMessageObj = new RNRemoteMessage(event.msg);
        const msg = RNRemoteMessageObj.parseMsgAllAttribute(event.msg);
        console.log('Data message received : ' + msg);
      });
    
      return (
        <SafeAreaView>
          <Text>Testing Text</Text>
        </SafeAreaView>
      );
    };

Manifest(仅应用程序部分,其他行是任何 android 应用程序的标准):

  <application
    android:usesCleartextTraffic="true"
    tools:targetApi="28"
    tools:ignore="GoogleAppIndexingWarning">
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    <meta-data
        android:name="push_kit_auto_init_enabled"
        android:value="true" />
</application>

这是“浓缩”日志:

16:23:53.989 HMSSDK_HmsMessageService:开始绑定 16:23:54.032 HMSSDK_HmsMessageService:处理消息启动 16:23:54.036 HMSSDK_HmsMessageService:onNewToken 16:23:54.043 HMSSDK_HmsMessageService:doOnNewToken:transactionId = null,internalCode = 0,subjectId:null,proxyType:null 16:23:54.046 HMSSDK_HmsMessageService:应用令牌 OnNewToken,subId:null 16:23:54.179 HMSSDK_HmsMessageService: onNewToken 来托管应用程序。 16:23:54.215 HMSSDK_HmsMessageService:onNewToken 以使用捆绑软件托管应用程序。 16:23:54.222 HMSSDK_HmsMessageService: 开始销毁

【问题讨论】:

    标签: android push-notification huawei-mobile-services huawei-developers huawei-push-notification


    【解决方案1】:

    您正在尝试发送通知消息,但onRemoteMessageReceived 用于接收数据消息,因此您无法读取日期字段。

    通知消息的自定义字段在用户点击消息时传输到应用程序,需要通过HmsPushEvent.onNotificationOpenedApp(callback)接收。

    更多详情,请参考this interface documents

    【讨论】:

    • 我已经检查并重新检查,但我不知道错误在哪里:( 实现是相同的。在这个问题之上,我用我的简单示例应用程序重写了这个问题。请你能帮帮我?
    • hi@Luca Parlapiano,我刚刚更新了我的答案,请参考。
    猜你喜欢
    • 1970-01-01
    • 2017-05-31
    • 2021-04-26
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 2015-04-10
    相关资源
    最近更新 更多