Make an Android service by listening to hardware keys

I am creating a Panic Alert application on Android for which I want the service to start in the background and acquire Partial-Wake-Lock to start, even when the screen is off. I want this service to listen for a volume key (or a combination of power and volume keys) by pressing for 3 seconds or more to start the service by sending panic messages.

Can I listen to key events by tying my service to any other system service? Or is there any other way to achieve my goal?

+4
source share
1 answer

To listen for a power button press, you register listeners for the SCREEN_ON and SCREEN_OFF events.

Android does not document any such way of listening for volume buttons, but you can look at this: Listen to volume buttons in the background?

0
source

All Articles