Android USB OTG: programmatically turn off power to the port

前端 未结 2 1045
-上瘾入骨i
-上瘾入骨i 2021-02-01 18:01

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.

I want to progra

2条回答
  •  清歌不尽
    2021-02-01 18:35

    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);
    

    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.

提交回复
热议问题