Android USB OTG:以编程方式关闭端口的电源 [英] Android USB OTG: programmatically turn off power to the port

查看:440
本文介绍了Android USB OTG:以编程方式关闭端口的电源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Suppose I have a USB-powered LED lamp connected through a USB OTG adapter to a Toshiba Excite 10 tablet running Android 4.0.3, which provides the power.

我想以编程方式从应用程序打开和关闭USB OTG主机端口的电源引脚. (理想情况下没有根,但是我会尽力而为).有什么想法吗?

I want to programmatically turn the USB OTG host port's power pins on and off from an app. (Ideally without root, but I'll take what I can get). Any ideas?

推荐答案

您必须对/sys目录具有写权限.生根使该过程非常容易.只需启动设备并发出正确的echo命令即可切换内核状态位,例如:

You must have write permission on /sys directory. Rooting makes the process very easy. Just root your device and issue the right echo command to toggle kernel status bits like :

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的适当权限.

Another way is to use libusb, dig the library for the function that cuts the power off. You can use android.hardware.usb.UsbManager to request proper permission for libusb.

这篇关于Android USB OTG:以编程方式关闭端口的电源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆