Android DOZE 模式 GCM 优先级

标签 android google-cloud-messaging android-6.0-marshmallow android-doze

对于 DOZE 模式测试,我正在 Android 6.0 上开发一个示例 GCM 应用。

如前所述,在 DOZE 模式下,设备不会为普通优先级 GCM 唤醒。我想检查一下。

根据文档 (https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message)

Normal priority. This is the default priority for message delivery. Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve battery. For less time-sensitive messages, such as notifications of new email or other data to sync, choose normal delivery priority.

我使用此链接中的一些服务器代码测试了我的应用程序。 https://stackoverflow.com/a/22169411/4242382

我从服务器发送的消息是这样的:

$msg = array
(
    'message'       => 'here is a message. message',
    'title'         => 'This is a title. title',
    'subtitle'      => 'This is a subtitle. subtitle',
    'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
    'vibrate'   => 1,
    'sound'     => 1
);

如您所见,没有设置优先级,所以在 DOZE 模式下我不应该立即得到它。但设备仍然会立即收到 GCM 消息。

测试方法

  1. 运行基于 GCM 的应用
  2. 通过从 adb shell ( link ) 发出命令来诱导 DOZE 模式 $ adb shell dumpsys 电池拔出 $ adb shell dumpsys deviceidle 步骤
  3. 从服务器发送消息 (phpfiddle)

预期行为:正常优先级 GCM 不会立即交付 观察到的行为:立即传递消息

DOZE 模式是否按照文档工作?我没有看到它发生,有人面临同样的情况吗?

最佳答案

我使用运行 API 23 的模拟器测试了非优先级 GCM 消息传递,并观察了记录的行为:当模拟设备处于打盹模式时,消息未被传递。退出 Doze 模式几秒钟后,收到消息。

我的测试应用是使用 Goggle Play Services 8.3.0 构建的。 API 23 的模拟器图像包含较旧版本的 Play 服务,这会导致在应用程序初始化更新到 8.3.0 时出现警告。我不知道如何在模拟器上做到这一点。该应用程序已成功注册并接收消息,因此我继续进行测试。

我将模拟设备置于打瞌睡模式:

$ adb shell dumpsys deviceidle enable

并重复:

$ adb shell dumpsys deviceidle step

我按照说明 provided here 使用 curl 发送消息.通过观察 logcat 输出确认消息接收。

deviceidle step 命令产生状态:IDLE_PENDING、SENSING、IDLE_MAINTENANCE 和 IDLE。对于除 IDLE 之外的所有用户,消息都会立即收到。未收到在 IDLE 中发送的消息。等待大约一分钟后,使用 deviceidle step 进入 IDLE_MAINTENACE 状态。几秒钟之内,保存的消息就送达了。

两个建议:

  1. 如果您没有使用 Play Services 8.3.0 进行构建,请更新到该版本。
  2. 使用 curl 和上面链接的说明发送测试消息,看看它是否会产生与您的服务器代码不同的行为。

关于Android DOZE 模式 GCM 优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33999016/

相关文章:

android - 如何从内部类调用 checkSelfPermission(android.content.Context,java.lang.String)

java - 将视频转换为 GIF

java - 密码获取错误::EVP_DecryptFinal_ex:解密错误

android - 仅在 Lollipop 中出现 GCM SERVICE_NOT_AVAILABLE 异常

Android,通过 GCM 与应用程序的两个实例进行通信

android - Android 6 Marshmallow 上的 setMyLocationEnabled( map 权限)

android - 错误 : Error: No resource found that matches the given name: attr 'buttonBarButtonStyle'

java - 修复 Google API task-android-sample 的内存不足错误

android - 如何从上下文中获取应用程序

android - 无法隐藏 Marshmallow 运行时权限对话框