Android - 关闭硬件按键灯

发布于 2024-10-01 12:51:04 字数 73 浏览 0 评论 0原文

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

Inside my app, I need a way to turn off the lights on the standard Android phone keys (Home, Menu, Back, and Search) - how can I do this programmatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜警司 2024-10-08 12:51:04

根据此页面,硬件按键背光可以通过使用超级用户权限写入文件系统中的特定文件来控制(即手机必须“root”):

问:如何控制键盘
背光?

A: 键盘背光可以
通过控制
/sys/class/leds/键盘背光/亮度。
看起来这是一个简单的开关
控制(回显“0”将其关闭,
回显“1”或更高的值将其打开)。
由于某种原因,默认系统
背光控制的东西似乎设置
这是“83”,但我不知道为什么。我
似乎看不出有什么区别
83 和任何其他数字之间。这
文件可供任何人读取,但仅限
root可写,所以你需要root
访问手机并对其进行操作
这边走。

因此,要以编程方式关闭背光,您可以调用 exec() 在运行时如下所示:

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

取决于您正在做什么,但之后检查 exec() 的结果以查看是否发生写入错误可能是明智的。

注意:我在自己的手机上测试了这一点,它似乎无需 root 权限即可工作。但是,并非每部手机都是如此,因此您可能会得到不同的结果。

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.

仙女 2024-10-08 12:51:04
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);
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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文