gpt4 book ai didi

安卓 USB OTG : programmatically turn off power to the port

转载 作者:IT老高 更新时间:2023-10-28 23:07:13 24 4
gpt4 key购买 nike

假设我有一个 USB 供电的 LED 灯,通过 USB OTG 适配器连接到运行 Android 4.0.3 的 Toshiba Excite 10 平板电脑,它提供电源。

我想通过应用程序以编程方式打开和关闭 USB OTG 主机端口的电源引脚。 (理想情况下没有root,但我会尽我所能)。有什么想法吗?

最佳答案

您必须拥有/sys 目录的写入权限。生根使该过程非常容易。只需root您的设备并发出正确的回显命令即可切换内核状态位,例如:

String[] command = { "/system/bin/sh", "-c", "echo xxx > /sys/bus/usb/devices/usb3/power/level", };
Runtime.getRuntime().exec(command);

另一种方法是使用libusb,在库中挖掘切断电源的功能。您可以使用 android.hardware.usb.UsbManager 为 libusb 请求适当的权限。

关于安卓 USB OTG : programmatically turn off power to the port,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14151077/

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