How to disable power button?

≯℡__Kan透↙ 提交于 2019-11-26 21:34:59

问题


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 ?


回答1:


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.




回答2:


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.




回答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)



来源:https://stackoverflow.com/questions/8036701/how-to-disable-power-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!