Example of data reading operation between Android device and external USB flash disk

Now more and more mobile phones support OTG function. Through OTG, data transmission can be realized with USB disks and other USB devices connected externally.

USB OTG (on the go), as a supplementary protocol to USB2.0, was proposed by usb-if in 2001. The background of its proposal is the rapid increase of mobile consumer electronic products, and the previous master-slave protocol standard of USB protocol makes the data transmission of these electronic products when leaving the PC difficult. OTG technology is the standard to solve this problem.

End to end interconnection between devices through OTG Technology

The OTG protocol stipulates that the device as the host is device a by default during connection, and device a is responsible for supplying power to the bus; The default device as device is device B (USB OTG standard adds an ID pin on the basis of full compatibility with USB2.0 standard; the default device is device a when the ID is lowered); Due to the integration of host controller and device controller, some devices can be used as both a device and B device, which is called dura role device.

Recently, this function has been used in the project. The box of Android 7.1 is used in the project to realize data operation with the inserted USB flash disk. Through a large number of data search, the functions required in the project are finally realized. Finding information mainly solves two problems:

I don't say much nonsense. I feel that I still like to go directly to the code. An open source framework is used in the project. The open source address is: https://github.com/magnusja/libaums 。

Code part:

Corresponding layout file:

File operation tool class:

Don't forget to add the following under app / build.grade:

And add permissions in androidmanifest.xml:

Time relations, not mapping, welcome to guide the exchange.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>