How to react to android power button properly - android

I want to make a walkie-talkie app using the power button as Push-to-talk.
Therefore i need to replace the button's behavoir to
Using onKeyDown onKeyUp or OnKeyLongPressed() trigger events works to receive, but after thre trigger event is processed, screen goes off.
What i have found searching
Overriding the power button in Android
How to hook into the Power button in Android?
doesn't help me since i can't get the Cyanogenmod to work on this phone.
Maybe you have some Idea.
Thank you in advance.

You cannot change the behavior of the power button, except via your own custom ROM mod (e.g., CyanogenMod).

Related

Disable touch screen in Android in accessibility service

I am developing an Android application for the deaf and blind using the accessibility service
Need to disable the touch screen, because android app is controlled through a third-party device
I tried to add a view to WindowManager and disable everything there (FLAG_NOT_FOCUSABLE, FLAG_NOT_TOUCHABLE), but as far as I understand, it disabled the touch screen only in this view, but not at all
I can request any type of permission except the root
EDIT:
Due to Android security, disabling the touchscreen is not possible without root, but you can use Proximity Sensor to disable touchscreen until first power button pressure
Congratulations and good will for you are working for a good cause.
Not sure exactly how to do this but One way is to create a full screen activity - hide navigation bar and soft navigation buttons also -- please refer this documentation
And 2. override onBackPressed and never allow it to call super.onBackPressed() or relaunch your app in OnPause() method.
Hope this helps somewhat.

Can I have a listener for the physical hardware button that is present on the side of the Android watch?

My android watch has a single hardware (physical) button on the side. Is it possible to program a listener for this button, so that it can be used as an additional control in my program?
I don't believe this is possible. The usual way to detect a standard button press (like Back) in Android is with an onKeyDown listener, and this doesn't fire in an Activity on Wear when the stem button is pressed (tested on both Wear 1.5 and the 2.0 dev preview).
It's always iffy to assert something is categorically not possible, because there's always the chance that someone will find a clever hack to make it happen. And I wouldn't mind being proved wrong. But until such a hack comes along, I'm going to say no, it's not.

FLAG_KEEP_SCREEN_ON does not work during keygaurd lock

Hi I am an Android newbie, I want to create an app which stays displayed even if the power button is pressed, I used,
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
but I had to press power button again to display the app, someone suggested me to use,
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
but it doesn't seem to work. Is there any work around ?
You can't prevent hardware keys overriding. Power button works on hardware level. Ur app will be unable to turn screen on after it was turned off by hardware.

Activate Android with touch instead of power button

We've got a tablet application for which we want to screen to timeout after a certain period, but would like the user to re-enable it by touching the screen instead of the 'power'-button on the side of the device.
What's the best approach (battery performance) to this?
Using a Partial Wake Lock (will the screen react?)
Disable the screen in some way, but keep everything (including touch response) working?
Other?
Any suggestions on this?
Gabriel,
Since this isn't possible by completely turning the screen off, you may want to just want to use a wake lock and dim the screen to its lowest setting as your 'timeout'. This way you can still accept screen touch events and 'wake' it from this state and bring it back to its previous brightness.
We've got a tablet application for which we want to screen to timeout after a certain period, but would like the user to re-enable it by touching the screen instead of the 'power'-button on the side of the device.
This is impossible except perhaps via custom firmware. If the screen is off, it will not respond to touch events.
Another thing you could do is use an app to turn screen off like ScreenStandby since it works in the background and can start on boot as well.
Out of curiosity, how can we go about contacting someone to help in creating a custom firmware like you did Gabriel?

Is there a way to make an android app respond to hardware buttons while phone locked?

I'm working on my first android app. So far I have an activity that reacts to clicks on the hardware volume controls. That's was easy to do, but I'm wondering if there is a way to make it so the app responds to these events from the hardware buttons even while the phone is locked?
I'm really looking for a confirmation of whether or not this can be done. If someone could confirm and give me the general idea of how to do it that would be awesome.
I have not done exactly this but I believe that if you put
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
in your Activity onCreate() you will be able to do what you want even if the screen is locked.

Categories

Resources