简体   繁体   English

Android - 使用google云消息传递的高优先级消息(使用corona sdk)

[英]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. 我正试图唤醒手机或使用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. 我正在使用razr maxx hd进行测试。 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;

From the following two links 从以下两个链接

GCM Priority GCM优先

Optimizing for Doze and App Standby 优化Doze和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. GCM尝试立即提供高优先级消息,允许GCM服务在可能的情况下唤醒休眠设备并打开与应用服务器的网络连接。

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

So obtain a device running Marshmallow or greater and put it to dose mode by running following commands 因此,通过运行以下命令,获取运行Marshmallow或更高版本的设备并将其置于剂量模式

$ 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. 当消息优先级高时,应该接收通知,类似地,当没有设置优先级或设置为正常时,通知将在延迟或唤醒设备时传送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM