简体   繁体   中英

Android - turn off hardware key lights

在我的应用程序内部,我需要一种方法来关闭标准Android手机按键(主页,菜单,后退和搜索)上的指示灯 - 如何以编程方式执行此操作?

According to this page , the hardware key backlights can be controlled by writing to a specific file in the filesystem with superuser privileges (ie 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM