问题
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
回答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.
回答2:
https://developers.google.com/cloud-messaging/concept-options?hl=en#setting-the-priority-of-a-message
In fact, it's related with Google Play Services version not Android version. Use "high" for priority.
回答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);
来源:https://stackoverflow.com/questions/31315057/how-to-send-a-high-priority-gcm