admin管理员组文章数量:1188999
I've seen that there is a lot of similar question with people having trouble regarding this topic, however I still couldn't a solution that worked for me. And so here I am..
I am trying to create an alarm feature. It has a usual default behaviour of an alarm - meaning the user can create any amount of alarms, at any time, set to trigger at any time. From reading the docs I found out:
Note: Neither setAndAllowWhileIdle() nor setExactAndAllowWhileIdle() can fire alarms more than once per nine minutes, per app.
The only possible solution that seemed possible was to combine the wakeLock with alarmManager. And that was followingly: The 1st intent would be captured in the doze mode, within the boardcast. Then I would check weather there are more alarms within that 9 minute doze period and if there were I would create a wakeLock till the last alarm of that period was executed. The wakeLock was of type:
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyApp::AlarmWakeLock");
However while the lock showed as acquired in the logs for some reason the wakeLock would not take effect and wake the device to allow the other alarms to trigger the broadcast. Why is that happening? I had added the required permissions for this action - android.permission.WAKE_LOCK, android.permission.SYSTEM_ALERT_WINDOW, android.permission.SCHEDULE_EXACT_ALARM
. And the PendingIntent that is supposed to fire that alarmReceiver is of type: PendingIntent.FLAG_UPDATE_CURRENT
and has always the same id with unique extras attached.
I tested this on multiple devices both physical/virtual with different API and the issue seems to persist across.
The last thing I thought would be the battery restriction, however the default clock app on the phone was not excluded from those restriction and still works as supposed so I do not think that play a role either.
Why is this occuring? Am I missing something in the code? Thank you, any help would be much appriciated
本文标签: javaHow to AlarmManager while the device is asleepStack Overflow
版权声明:本文标题:java - How to AlarmManager while the device is asleep? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738364799a2081411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论