gpt4 book ai didi

Android - 关闭硬件按键灯

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:09:37 25 4
gpt4 key购买 nike

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

最佳答案

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

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.

因此,要以编程方式关闭背光,您可以调用 exec()在运行时像这样:

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

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

注意:我在我自己的手机上测试过这个,它似乎在不以 root 身份运行的情况下工作。但是,并非每部手机都是这种情况,因此您可能会得到不同的结果。

关于Android - 关闭硬件按键灯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4152053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com