Detect power button pressed in Accessibility Service - android

I need to open application when power and volume+ buttons long pressed.
Does its possible to detect power button pressing in Accessibility Service? Or maybe exist another way to do this?

You can detect the Volume button up or down on the onKeyEvent() method, but you can't detect the power button, due to the android functionality.

Related

How to press the Physical Button (like volume or power button ) in Android Pragmatically

Like the combination of power button and volume down button - takes a screenshot of the phone...
Similarly I am trying to access volume up and power button with long press in my app and provide a shortcut. Is this possible?

Headset Button as a trigger even the application is in background

I'm creating a music player in android and I want that when I press the headset button, the song will play/pause even if my application is in the background/foreground. I'm using a service class.
How can I trigger the event when the headset button is pressed even if my app is in the background?
Use the guide. There is a description of hardware buttons usage.

Disable or override Power button onClick method

I'm working on application which shouldn't allow action like switching off screen which is performed by clicking power button. There could be long click action on this button still working. Anyone know how to disable switch off screen in application setting flag KEEP_SCREEN_ON didn't block it.
Thank you in advance.
i don't think you can capture the event of clicking on the power button.
the events of the screen occur after they have occurred.
you might be able to capture the power button if the device is rooted (or if the app is a system app), but i'm not sure how.
the only thing that is close to what you want (that i know) is to listen to the event of screen being turned off, and then cause the screen to be turned on ,which (according to what i remember, might be wrong on this) requires the permission "DEVICE_POWER" .

Android update widget on hardware button press

Is it possible to update an android widget when hardware button is pressed (side volume button, for instance)?
No, this is not possible as you cannot listen to events on the volume, power, home, back and menu buttons if your app is not in the foreground.
On some device you may listen to the camera button, but that is present on very few devices.

Android mute button

Some new Android devices have a mute button like Iphone. Its an actual physical button that allows you to mute an incoming call instead of long pressing the volume down hardware control or the pressing the power button.
my question: What is the keycode event for this or how can i capture it so i can get my app to respond to it ?
I think you're looking for KeyEvent.KEYCODE_MUTE. Note that no flagship Android devices have this button, so you are left to the mercy of whether or not the manufacturer's OS actually sends this event or not.

Categories

Resources