简体   繁体   English

Huawei Push Kit API - 从通知的有效负载中读取数据 - onRemoteMessageReceived 不工作

[英]Huawei Push Kit API - Read data from payload of Notifications - onRemoteMessageReceived don't work

I want to read the date field from payload of this push notification but the api doesn't seem to work:(我想从这个推送通知的有效负载中读取日期字段,但 api 似乎不起作用:(

I'm now from hms Huawei, i have read this tutorial: HMS-Plugin-Guides-V1我现在来自hms Huawei,我已经阅读了这个教程: HMS-Plugin-Guides-V1

all part is completed except d point, -> error of overwriting.除 d 点外,其他部分均已完成,-> 覆盖错误。

When i send a notification, and i push on it.当我发送通知时,我会推送它。 All ok my app will open.一切正常,我的应用程序将打开。 But i can't read notification body.但我无法阅读通知正文。

In the log i see the notification service start -> take token and immediately kill itself... i don't understand where is problem.在日志中,我看到通知服务启动 -> 获取令牌并立即自行终止......我不明白问题出在哪里。

Notify JSON通知 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"
        ]
    }
}


My app code:我的应用程序代码:

   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 (only application section, other line is standard for any android app):清单(仅应用程序部分,其他行是任何 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>

this is 'condensed' log:这是“浓缩”日志:

16:23:53.989 HMSSDK_HmsMessageService: start to bind
16:23:54.032 HMSSDK_HmsMessageService: handle message start
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: Apply token OnNewToken, subId: null
16:23:54.179 HMSSDK_HmsMessageService: onNewToken to host app.
16:23:54.215 HMSSDK_HmsMessageService: onNewToken to host app with bundle.
16:23:54.222 HMSSDK_HmsMessageService: start to destroy

You are trying to send a Notification messages, but onRemoteMessageReceived is used to receive a data message, so you cannot read the date field.您正在尝试发送通知消息,但onRemoteMessageReceived用于接收数据消息,因此您无法读取日期字段。

User-defined fields of notification messages are transferred to the app when a user clicks a message and need to be received through the HmsPushEvent.onNotificationOpenedApp(callback) .通知消息的自定义字段在用户点击消息时传递给应用,需要通过HmsPushEvent.onNotificationOpenedApp(callback)接收。

For more details, pls kindly refer to this interface documents .更多详细信息,请参阅此接口文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM