Android - 关闭硬件按键灯
在我的应用程序中,我需要一种方法来关闭标准 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据此页面,硬件按键背光可以通过使用超级用户权限写入文件系统中的特定文件来控制(即手机必须“root”):
因此,要以编程方式关闭背光,您可以调用 exec() 在运行时如下所示:
取决于您正在做什么,但之后检查 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"):
So to turn off the backlight programmatically, you could invoke exec() on the Runtime like so:
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.