2

I have an issue when using HMS push kit for sending DATA notifications to make sure onMessageReceived is called but the problem is that for the same JSON body the notification received sometimes arrive as data and on message received is called and other times it's received as notification and is handled by the system tray this is the laravel backend code I'm using:

     $body = [
            "validate_only" => false,
            "message" => [
                "data" => json_encode($this->message),
                "token" => $this->tokens
            ]
        ];
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => 'https://push-api.cloud.huawei.com/v1/{some_id}/messages:send',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => json_encode($body),
            CURLOPT_HTTPHEADER => array(
                'Content-Type: application/json; charset=UTF-8',
                'Authorization: Bearer ' . $this->access
            )
        ));
        $response = curl_exec($curl);
        curl_close($curl);

how can I make sure it always arrives as Data?

OshiniRB
  • 578
  • 1
  • 7
  • 21
  • hi@Nickola Jarjous, According to my development experience, data messages cannot be converted to notification messages. How did you find it converted to a notification message? – zhangxaochen Oct 08 '21 at 07:22

1 Answers1

0

With downlink message sending by the server, please refer to below webpage and information. Please make sure your message configuration is exactly same as the requirement. Meanwhile please make sure your server or team don’t send push message to your test device. Because data message structure is different from notification message. Data message is impossible to be received as a notification message. https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-server-dev-0000001050040110

enter image description here

{ "validate_only": false, "message": { "data": "{'param1':'value1','param2':'value2'}", "token": [ "pushtoken1", "pushtoken2" ] } }

You can try using Huawei AG console to send a data message as below. If below sending works well, it proves your device to receive data message very well. So you will double check your server confirmation for the push data message. https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/msg-sending-android-0000001136294192

enter image description here

The below webpage is for data message development. https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-basic-receivemsg-0000001087370610

If you still have issue after above test and check, please try to catch some logcat logs so we can analyze the logs for more information. For the guide of logcats: https://developer.android.com/studio/command-line/logcat

Zinna
  • 1,947
  • 2
  • 5
  • 20
  • Thank you for your replay as you can see from my PHP code it is indicating that I'm sending a data notification just as you hinted but even for the same payload the notification received on Android side is not always data sometimes it's received as Notification for some reason – Nickola Jarjous Oct 06 '21 at 10:14