1

I want to read the date field from payload of this push notification but the api doesn't seem to work :(

I'm now from hms Huawei, i have read this tutorial: HMS-Plugin-Guides-V1

all part is completed except d point, -> error of overwriting.

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


{
    "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):

  <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

2 Answers2

0

You are trying to send a Notification messages, but onRemoteMessageReceived is used to receive a data message, so you cannot read the date field.

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).

For more details, pls kindly refer to this interface documents.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • I have checked and recheck but i don't know where is the mistake :( the implementation is the same. On top of this questione i have rewrite this question with my simple exemple app. Please can you Help me? – Luca Parlapiano Oct 06 '21 at 09:56
  • hi@Luca Parlapiano, i just updated my answer,pls kindly refer. – zhangxaochen Oct 07 '21 at 12:03
0

You need "notification" OR "data" object.

According to Huawei developer Push Kit Server Development Guide Downlink Message Sending

{
"validate_only": false,
"message": {
    "data": "{'param1':'value1','param2':'value2'}",
    "token": ["pushtoken1"]
}}
moken
  • 3,227
  • 8
  • 13
  • 23