当其他应用程序获取唤醒锁时收到通知
我想知道在 android 中是否可以执行以下操作。我想让我的应用程序在手机唤醒时执行特定任务。每当其他应用程序获取唤醒锁来执行其任务时,我希望我的应用程序执行自己的操作。
我可以使用广播接收器通过意图获得有关此事件的通知吗?如果是这样,如果其他应用程序在我的任务结束之前完成,会发生什么情况?
我问的原因是我不想唤醒手机来完成我的任务并影响电池寿命。我想利用唤醒锁的机会来做我的事情。
I am wondering if the following is possible in android. I want to have my application do a certain task whenever the phone get awoken. Whenever some other application acquires a wake lock to do it's task, I want my application to do something of its own.
Can I get notified through an intent using a broadcast receiver about this event? If so, what will happen if that other application finishes before my task ends?
The reason I'm asking is that I don't want to wake the phone up to do my task and affect the battery life. I want to take the opportunity of the wake lock to do my thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 AlarmManager 与 RTC 或 ELAPSED_REALTIME 类型一起使用。
http://developer.android.com/reference/android/app/AlarmManager .html#RTC
当闹钟响起时,设备不会被唤醒。下次手机唤醒时,您的闹钟就会触发。
You could use AlarmManager with RTC or ELAPSED_REALTIME type.
http://developer.android.com/reference/android/app/AlarmManager.html#RTC
The device is not woken up when your alarm goes off. the next time phone is awake your alarm is triggered.
不。
然后就不要叫醒手机了。遵循 nandeesh 的建议并使用非
_WAKEUP
闹钟。不过,您仍然需要WakeLock
,因为设备可能会在您完成任何工作之前重新进入睡眠状态。No.
Then don't wake up the phone. Follow nandeesh's suggestion and use a non-
_WAKEUP
alarm. You will still need aWakeLock
, though, because the device may fall back asleep before you complete whatever your work is.