Android M(预览版)打ze模式和AlarmManager [英] Android M (preview) Doze mode and AlarmManager

查看:55
本文介绍了Android M(预览版)打ze模式和AlarmManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在操作系统进入打ze模式时测试我们的Android应用程序的行为.我正在使用运行Android API 23(修订版1)的模拟器. 应用程序使用类型为ELAPSED_REALTIME_WAKEUP的setInexactRepeating方法通过AlarmManager启动服务.我将警报设置为大约每三分钟触发一次(仅用于测试目的).经过几次尝试(官方指南尚不清楚),我通过锁定模拟器的屏幕并运行dumpsys建议的命令,成功将模拟器置于IDLE状态. 当设备处于空闲状态时,我仍然可以看到警报正在启动该服务. 这不应该是预期的行为.我期待警报被停止. 这是一个错误吗?还是我错过了什么?

I'm trying to test the behavior of our Android app when the OS goes in Doze mode. I'm using an emulator running Android API 23 (Revision 1). The application launches a Service through the AlarmManager using the method setInexactRepeating with type ELAPSED_REALTIME_WAKEUP. I set the alarm to fire approximately every three minutes (only for testing purposes). After several attempts (the official guide is very unclear) I succeed to put the emulator in IDLE state by locking the screen of the emulator and running dumpsys suggested commands. When the device is IDLE I'm still able to see the Service being launched by the alarm. This should not be the expected behavior. I was expecting the Alarm be stopped. Is this a bug? Or am I missing something?

推荐答案

要进行测试,请使用下面的代码.

For test use code below.

adb shell dumpsys deviceidle enable 
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle step
adb shell dumpsys deviceidle force-idle

使用setAndAllowWhileIdle强制唤醒智能手机.

Use setAndAllowWhileIdle for force smartphone wakeup.

在我的情况下,我使用这个:

In my case I use this:

if (android.os.Build.VERSION.SDK_INT > 22) {
   am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
} else {
   am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender);
}

我相信应该停止警报了.

I believe that the expected is the Alarm be stopped.

这篇关于Android M(预览版)打ze模式和AlarmManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆