How to disable power button?
Asked Answered
H

3

12

Is it possible to override the functionality of the android power button ? I want to 'disable' the power button. My plan is to override the functionality of this button to do nothing ( {}; ) Well my main idea is to disable the turning the screen off.

I want when someone press the power button nothing to happen.

How can I do this ?

Howlend answered 7/11, 2011 at 12:46 Comment(5)
IMO this is not good behaviour. I'd uninstall an app that does this. If you want to keep the screen on you could aquire the PowerManager.WakeLockBemis
I don't think it is possible.Enfleurage
That doesn't seem like a good idea. You can keep the phone from automatically going to sleep, but if the user wants to turn the screen off (s)he should be able to do it. I know I'd be pretty angry at the app for doing this.Pillowcase
If the user doesn't want this behavior he/she will not install the app at all. My goal is to make app that will delay the screen off for few second and before the turning off I want to make some animations.Howlend
Now you can: #10817867Eleven
S
9

Is it possible to override the functionality of the android power button ? I want to 'disable' the power button.

Fortunately, this is not possible, except perhaps via custom firmware.

Storehouse answered 7/11, 2011 at 13:38 Comment(2)
why being not possible is a "fortunately"Plummet
@B.shruti: Because disabling the power button is not something an ordinary app should be able to do. Among other things, it would make it easier for malware to prevent users from removing that malware by rebooting in safe mode.Storehouse
S
3

It works on Cyanogenmod: http://review.cyanogenmod.com/#/c/18924/4/core/res/AndroidManifest.xml you would need the android.permission.PREVENT_POWER_KEY permission.

Btw one good scenario is to use the power button as a camera shutter button (if the device does not have a dedicated one).

Afaik system apps can intercept the power button normally.

Stoddart answered 14/7, 2012 at 23:18 Comment(1)
This site can’t be reached :(Plummet
S
-3

Try implementing onKeyDown, and if the given key pressed keycode is KEYCODE_POWER and the action is ACTION_DOWN and right after it ACTION_UP return true (means you handled this key press)

Swett answered 7/11, 2011 at 12:53 Comment(3)
onKeyDown is NOT called when the power button is pressed :(Howlend
Hm... weird. Why do they have a constant "KEYCODE_POWER" then? Check and see if they give any piece of info there.Swett
So Android can use it internally.Savoie

© 2022 - 2024 — McMap. All rights reserved.