How can I read files from usb device on android? -
i'm trying create file explorer through connected usb devices(via otg or usb ports on android tv). need path "/storage/sda4" , device identifier, , can work device through simle android class file. sounds simple can't find info this, file explorers can (for example esexplorer). ok, find simple way connected usb devices identifier
usbmanager usbmanager = (usbmanager) context.getsystemservice(context.usb_service); usbmanager.getdevicelist();
but how can info path? devicename contains "/dev/bus/usb/00x" can't me, need simple emulated android path ("/storage/sda4"). page https://developer.android.com/guide/topics/connectivity/usb/host.html tells need usbinterfaces , make usbconnection bulk transfer , other bullshit, done didn't find path device or other info usb file list.
ok, find way (that don't requires permission!) path connected devices
storagemanager storagemanager = (storagemanager) context.getsystemservice(context.storage_service); method getvolumelistmethod = storagemanager.class.getdeclaredmethod("getvolumelist"); object[] storagevolumelist = (object[]) getvolumelistmethod.invoke(storagemanager);
and works need identify device(because want cache files of different usb storages) can volume object mstorageid, mdescriptionid, mprimary, mremovable, memulated, mmtpreservespace, mallowmassstorage, mmaxfilesize, mowner, muuid, muserlabel, mstate, msubsystem. none of can not identify device: mdescriptionid , mstorageid unique fot usb port, muuid null, muserlabel not unique.
environment.getexternalfilesdirs() won't help, don't provide device id , works 1 device.
i find similar question here, has no right answer android list files usb drive.
well, simple way list of usb devices path , identifier exists?
all need path "/storage/sda4" , device identifier, , can work device through simle android class file
no, because you not have arbitrary access removable storage, including usb otg drives, on android 4.4+.
all file explorers can (for example esexplorer)
pre-installed "file explorer" apps may have additional rights granted them device manufacturer or custom rom developer. otherwise, not have arbitrary access removable storage.
is simple way list of usb devices path , identifier exists?
not filesystem path, no. getstoragevolumes()
on storagemanager
give list of storage volumes, includes external storage , removable storage. can use createaccessintent()
on storagevolume
ask user permission work volume. if grant permission, uri
that:
serves temporary identifier volume (i.e., no longer usable identifier if user ejects media, until then, can distinguish 1 volume another), and
lets work portion of contents of volume, though using
uri
values, not filesystem paths
Comments
Post a Comment