【发布时间】:2010-11-11 06:58:29
【问题描述】:
在我的应用程序中,我需要一种方法来关闭标准 Android 手机按键(主页、菜单、返回和搜索)上的灯 - 我如何以编程方式做到这一点?
【问题讨论】:
在我的应用程序中,我需要一种方法来关闭标准 Android 手机按键(主页、菜单、返回和搜索)上的灯 - 我如何以编程方式做到这一点?
【问题讨论】:
根据this page,硬件按键背光可以通过以超级用户权限写入文件系统中的特定文件来控制(即手机必须“root”):
问:如何控制键盘 背光?
A:键盘背光可以 通过控制 /sys/class/leds/keyboard-backlight/亮度。 看来这是一个简单的开关 控制(回显“0”将其关闭, 回显“1”或更高会打开它)。 由于某种原因,默认系统 背光控制的东西似乎设置 这到“83”,但我不知道为什么。一世 似乎看不出任何区别 在 83 和任何其他数字之间。这 任何人都可以读取文件,但只有 可由root写,所以你需要root 访问手机以对其进行操作 这边。
所以要以编程方式关闭背光,您可以像这样在运行时调用exec():
Runtime r = Runtime.getRuntime();
r.exec("echo 0 > /system/class/leds/keyboard-backlight/brightness");
取决于你在做什么,但可能明智的做法是事后检查 exec() 的结果,看看是否发生了写入错误。
注意:我在自己的手机上对此进行了测试,它似乎可以在不以 root 身份运行的情况下工作。但是,并非每部手机都是如此,因此您可能会得到不同的结果。
【讨论】:
sys 挂载在/sys 中,这将呈现到/sys/class/leds/button-backlight/brightness 的路径 - 例如,适用于 Elephone P5000。
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);
【讨论】: