Receive volume key press events when phone is in deep sleep

Deadly 提交于 2019-12-03 21:43:43

I'm trying to catch Volume Up/Down pressing events when phone is in deep sleep mode.

By definition, that is impossible.

In Activities onCreate method I set a WakeLock

Then you are not in sleep mode.

then I lock my phones screen by pressing on a power button application stop receiving broadcast events

There are a few possibilities here. One is that your process was terminated, as it is no longer needed. Once you no longer have any foreground activities, your process is eligible to be terminated to free up memory for other apps, and that can happen at any point. Another possibility is that Android simply does not send that broadcast when the screen is off.

I did pretty much the same thing, but i achieved it by changing the source codes. i have explained that below.

whenever your phone goes to sleep , your MediaPlaybackService.java will not listen to keyEvents, but MediaButtonIntentReceiver.java will, so receive the intent here of volume up and down, and broadcast an intent and receive it in MediaPlaybackService.java, but keep one thing in mind you can't change the UI from here , so you can broadcast another intent from the service and make your MediaPlaybackActivity.java receive it , this will change the UI as soon as your screen wakes up.

FYI: when the screen is off, the PhoneWindowManager.java queues all the continuous intents and as soon as you release the button it will apply all the intents at once.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!