Search code examples
androidandroid-studioaccessibilityserviceaccessibility

Disable power button in android didn't work


I am developing an Android application for the deaf using the accessibility service

The problem is that deaf people do not need a power button because they will use another device

I tried to call this code

val commandLine = "input keyevent KEYCODE_POWER"
Runtime.getRuntime().exec(commandLine)

And it didn't work.

Moreover, the device didn't hook the power button press

I may use the GLOBAL_ACTION_LOCK_SCREEN, but only supported from API 28, but a minimum of 21 is needed

Getting the root and changing the system settings is not a good choice, because not for developers, the root can break the security

Tested on these devices:

  • Samsung S8+ API 29
  • PIXEL 2 API 28
  • PIXEL 2 API 27

Solution

  • This ... doesn't works according to user privacy :)