-5

I'm aware that this is a commonly asked question, but most questions are quite old, and I was hoping that the situation has changed.

I am looking to activate an application feature from the phone's locked state by pressing the volume up button five times in a row, without having to resort to using a wakelock. This feature should be activatable at any time using the volume while the phone is locked.

I have observed that some phones are able to detect volume button presses (e.g. two volume down presses will load the Camera application), but I have not been able to find out how these apps do it. I figured that if these phones are able to do it, then surely what I'm trying to do is possible?

1 Answers1

0

The KeyListener won't run when the application is paused (which it is if the screen is locked).

But there is a quite clever workaround: play some music (probably silence) and listen to volume changes. See here for more information on how to do it. AFAIK the above behavior hasn't changed and you mostly likely will have to resort to above workaround.
I'd love to be corrected on that as I've needed this myself.

Ch4t4r
  • 1,387
  • 1
  • 11
  • 30
  • Which answer in the linked thread should I be using as reference here? And regarding the workaround you mentioned, I'm assuming that this is essentially a wakelock, which means battery drain correct? – Long Hoang Tran Aug 14 '17 at 09:16
  • It's not exactly a wakelock but behaves like one. Sadly there is no way around it. Refer to the answers by ssuukk and joe. – Ch4t4r Aug 14 '17 at 09:20