How to send a high-priority GCM?
Solution 1
Setting priority to 10 is the correct thing to do, but it does not work with the version of Android M released at I/O. It has been fixed, and priority 10 messages will work as expected with the public release.
Solution 2
In fact, it's related with Google Play Services version not Android version. Use "high" for priority.
Solution 3
Just add this into your File (.php, .jsf, etc):
$fields = array(
'registration_ids' => $android,
**'priority' => 'high',**
'data' => array( 'message' => $message,
'title' => $title,
'created_at' => $created_at,
'is_background' => $is_background,
'pantallaMostrarPushAndroid' => "pushNotificationNormal")
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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));
// Execute post
$resultAndroid = curl_exec($ch);
Related videos on Youtube
jlopes
Updated on October 14, 2022Comments
-
jlopes over 1 year
I'm using a Nexus 5 with Android M Preview.
My problem that I'm trying to solve is:
Network access is disabled, unless your app receives a high priority Google Cloud Messaging tickle.
What I'm doing is:
I put the phone into Doze mode and then I send a push notification with the priority with value 10 and I'm expecting to have internet access for a brief moments, but this is not working.
Should I use other type of notifications? There are any documentation already available?
Thanks.
Android M changes: https://developer.android.com/preview/behavior-changes.html
What I found about GCM priority messages: https://developers.google.com/cloud-messaging/server-ref
-
jlopes almost 9 yearsThanks for your answer ;)
-
A.D. almost 9 years@morepork: So it won't work in any Preview Release or do i miss the point? Do you have a link?
-
Wonil over 8 yearsPlease see developers.google.com/cloud-messaging/…
-
Mubashar over 6 yearsif we don't set priority, what will be the default priority High or normal?