How to read OTG USB storage

南楼画角 提交于 2019-12-03 09:02:20

I've looked at your other questions regarding OTG access, and I think you're making it hard on yourself. The easiest way IMO to access/read/write OTG on a very wide range of devices is by querying all these directories, and using shell to read/write to them:

/storage/UsbDriveA     (all Samsung devices)
/storage/USBstorage1   (LG G4, V10, G3, G2, other LG devices)
/storage/usbdisk       (Moto Maxx, Turbo 2, Moto X Pure, other Motorola devices)
/storage/usbotg        (Sony Xperia devices, Lenovo Tabs)
/storage/UDiskA        (Oppo devices)
/storage/usb-storage   (Acer Iconia Tabs)
/storage/usbcard       (Dell Venue -- Vanilla Android 4.3 tablet)
/storage/usb           (HTC One M7, and some Vanilla Android devices)

Tested on my collection of devices (and a few others'), and a quick trip to Bestbuy for testing the latest flagships. The only popular devices I know I'm missing are Hawuei/Xioami devices based in China, which are becoming popular in English countries.

You would be using Runtime.exec() or ProcessBuilder and testing the length of the ls command output on each directory (to find the mounted USB directory), and cp or redirection > to write files to the pendrive, and cat to read off the pendrive.

Hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!