微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – Android – 具有谷歌云消息传递的高优先级消息(使用电晕sdk)

我正试图唤醒手机或使用GCM让灯光闪烁.我收到的信息很好,但是设置高优先级或根本没有优先权.我正在使用razr maxx hd进行测试.这里有什么我想念的吗?

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,CURLOPT_SSL_VERIFYPEER,false );
curl_setopt( $ch,CURLOPT_POSTFIELDS,json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
最佳答案
从以下两个链接

GCM Priority

Optimizing for Doze and App Standby

您可以推断出高优先级消息

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.

并为正常的消息

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

正如您在以下question的答案中所看到的那样

你永远不能确定Android设备是否处于睡眠模式,因为Android版本低于Marshmallow,对于运行Marshmallow或更高版本的设备,有打盹模式.

因此,通过运行以下命令,获取运行Marshmallow或更高版本的设备并将其置于剂量模式

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

您可能需要多次运行第二个命令.重复此过程,直到设备状态变为空闲.

现在尝试发送具有高优先级和普通优先级的推送通知.当消息优先级高时,应该接收通知,类似地,当没有设置优先级或设置为正常时,通知将在延迟或唤醒设备时传送.

原文地址:https://www.jb51.cc/android/429963.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐