Android - turn off hardware key lights

纵然是瞬间 提交于 2019-11-28 22:08:18

According to this page, the hardware key backlights can be controlled by writing to a specific file in the filesystem with superuser privileges (i.e. phone must be "rooted"):

Q: How can I control the keyboard backlight?

A: The keyboard backlight can be controlled via /sys/class/leds/keyboard-backlight/brightness. It appears that it's a simple on-off control (echoing '0' turns it off, echoing '1' or higher turns it on). For some reason, the default system backlight control stuff seems to set this to "83", but I don't know why. I can't seem to see any difference between 83 and any other number. The file is readable by anyone, but only writable by root, so you'll need root access to the phone to manipulate it this way.

So to turn off the backlight programmatically, you could invoke exec() on the Runtime like so:

Runtime r = Runtime.getRuntime();
r.exec("echo 0 > /system/class/leds/keyboard-backlight/brightness");

Depends on what you are doing, but would probably be wise to check the result of exec() afterwards to see if a write error occurred.

Note: I tested this on my own phone and it seems to work without acting as root. However, this may not be the case on every phone, so you may have different results.

This is applicable only for the device samsung devices:

To get the BackLight sate:
int backLight = Settings.System.getInt(getContentResolver(), "button_key_light");
// if it return -1 it means that light is on
// if it return 0 the light is off
// some time it will return values like 600(1.5 sec)
if you want to put the backLight as off u can do like this

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