Android update widget on hardware button press - android

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.

Related

Detect power button pressed in Accessibility Service

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.

Android Soft Button and Hardware Button

I want to create an app that is not usable by the user but performs some functionality outside the app, the app just run in the foreground and listen to the press of android hardware/software buttons, the likes of Power button, home button, volume up and down. It triggers a call when for instance, the volume up button is pressed down for 5 secs and notification appears.
I have checked solutions like this
Intercepting the back button
How to override the behavior of the volume buttons in an Android application?
But this solutions have something to do with the user accessing the app directly, i mean to perform this functionalities you have to be on the app which i don't want.
The app was suppose to be run on a smart watch which runs android OS. I was thinking if i can perform this on android phone, it should be easier on the smart watch.
Note:
The App is for targeted users, who will be trained to understand that behavior.

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?

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.

Back button functionality in android

For time being I don't have back button in my android device, For this I need to implement back button functionality.
Using sensors like proximity or light sensors. So that when user taps or near a finger to proximity any application which is on foreground should come back to previous activity (it should acts like back button).
How to do this in android ?
Can't you just call onBackPressed() ?

Categories

Resources