Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to wake my phone or get the light blinking using GCM. I'm getting the messages just fine but theres no difference in setting a high priority or none at all. I'm using a razr maxx hd to test. is there anything I'm missing here?

<?php
// API access key from Google API's 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;
like image 793
hamobi Avatar asked Mar 23 '16 01:03

hamobi


1 Answers

From the following two links

GCM Priority

Optimizing for Doze and App Standby

you can deduce that for high priority message

GCM attempts to deliver high priority messages immediately, allowing the GCM service to wake a sleeping device when possible and open a network connection to your app server.

and for normal message

Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve battery.

and as you can see from answer for the following question

you can never be sure that Android device is in sleep mode for Android version less than Marshmallow, for devices running Marshmallow or higher there is doze mode.

So obtain a device running Marshmallow or greater and put it to dose mode by running 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 state changes to idle.

Now try sending the push notification with high priority and normal priority. When the message priority is high the notification should be received and similarly when no priority is set or set to normal the notification will be delivered with some delay or when you wake up the device.

like image 74
Anirudha Agashe Avatar answered Nov 11 '22 17:11

Anirudha Agashe