Recognize the volume button when the screen is off.

I am trying to find out when the user presses the volume when the screen is off to update the action. From what I read, BroadcastReceivers (I think) does not work when the phone is sleeping, and therefore the only way to do this is to keep activity using PARTIAL_WAKE_LOCK. My application is a basic one that should not use too much battery, but I am concerned that using PARTIAL_WAKE_LOCK may drain the battery (which does not meet the purpose of recognizing button presses when the screen is off).

Would PARTIAL_WAKE_LOCK really be a problem for the underlying application? If so, what is the best way to do this, and if not, what is the best way to use PARTIAL_WAKE_LOCK (i.e. when should I acquire / release it)?

Thanks in advance.

+4
source share
2 answers

There are two questions; I am going to focus on the WAKELOCK part.

Locks for waking up are notorious for shaking the battery of a mobile device. Understand that the device turns off the screen, then turn off the screen before turning off the CPU and entering standby mode. This is a very important step for your phone as it saves battery.

, , .

, , ; , .

, :

1) , /.

2) WakeLock.aquire(..), . , , , , . (. http://goo.gl/FkrO8)

3) AlarmManager ; , , .

4) API JobScheduler ( L), API. (. http://goo.gl/Z1AqSn)

+8
0

All Articles