Android - high priority messages with google cloud messaging (using corona sdk)

I'm trying to wake my phone or blink using GCM. I get messages just fine, but there is no difference in setting high priority or not at all. I am using razr maxx hd for testing. is there something i'm missing here?

<?php // API access key from Google API Console define('API_ACCESS_KEY', 'blee'); // prep the bundle $msg = array ( 'body' => 'this is my nice body', 'sound' => 'misc/androidnotification.mp3', 'custom' => array( 'route' => '/beee' ) ); $fields = array ( 'collapse_key' => 'test', "time_to_live" => 0, 'priority' => 'high', 'to' => 'mykey', 'data' => $msg, ); $headers = array ( 'Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json' ); $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' ); curl_setopt( $ch,CURLOPT_POST, true ); curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ); $result = curl_exec($ch ); curl_close( $ch ); echo $result; 
+5
source share
1 answer

Of the following two links

GCM Priority

Optimization for Doze and App Standby

you can conclude that for a high priority message

GCM tries to immediately send high priority messages, which allows the GCM service to wake the sleeping device as much as possible and open a network connection to your application server.

and for a regular message

Messages with normal priority will not open network connections on the sleeping device, and their delivery may be delayed to save battery.

and as you can see from the answer for the following question

you can never be sure that the Android device is in sleep mode for the Android version smaller than Marshmallow, for devices working with Marshmallow or higher, there is a dose mode.

So, get a device that works with Marshmallow or higher, and put it in dose mode by running the following commands

 $ adb shell dumpsys battery unplug $ adb shell dumpsys deviceidle step 

You may need to run the second command more than once. Repeat it until the device status changes to idle.

Now try sending a push notification with a high priority and a normal priority. When the priority of the message is high, the notification should be accepted in the same way, if the priority is not set or is not set to normal, the notification will be delivered with some delay or when the device wakes up.

+3
source

Source: https://habr.com/ru/post/1245595/


All Articles