How can I read files from usb device on android?

丶灬走出姿态 提交于 2019-12-05 10:49:48

All I need for this is a path something like "/storage/sda4" and device identifier, and then I can work with device through simle android class File

No, because you do not have arbitrary access to removable storage, including USB OTG drives, on Android 4.4+.

all file explorers can do it (for example ESExplorer)

Pre-installed "file explorer" apps may have additional rights granted to them by the device manufacturer or custom ROM developer. Otherwise, they too do not have arbitrary access to removable storage.

is a simple way to get list of usb devices with path and identifier exists?

Not with a filesystem path, no. getStorageVolumes() on StorageManager will give you a list of storage volumes, which includes external storage and removable storage. You can then use createAccessIntent() on StorageVolume to ask the user for permission to work with the volume. If they grant permission, you get a Uri back that:

  • Serves as a temporary identifier for the volume (i.e., will no longer be usable as an identifier if the user ejects the media, but until then, can distinguish one volume from another), and

  • Lets you work with a portion of the contents of that volume, though using Uri values, not filesystem paths

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