I need to import / export some data from / to a usb stick. Is there a way to get the path of the mounted usb devices?
My code looks something like this:
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while(deviceIterator.hasNext()){
UsbDevice device = deviceIterator.next();
UsbInterface deviceInterface = device.getInterface(0);
if(deviceInterface != null && deviceInterface.getInterfaceClass() == UsbConstants.USB_CLASS_MASS_STORAGE){
// check if path "mnt/usb_storage/*" exist
}
}
I can search if the path "mnt/usb_storage/*" exists when the device is a mass storage. This works fine if only one usb mass storage is attached or the app is in foreground when a second usb mass storaged is attached. If you wonder, yes there are Android devices with multiple usb ports.
Is there no way to get the path when I have the UsbManager/UsbDevice/UsbInterface? Is the path on all devices like "mnt/usb_storage/*"?
Update 1:
Target Android Version 5.1 Requirement: "Filechooser" has to be integrated inside the app, filter for folders, file names und file types have to be applied.
Update 2:
As suggested by @greenapps I gave "ACTION_OPEN_DOCUMENT_TREE" a try:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
intent.putExtra("android.content.extra.FANCY", true);
intent.putExtra("android.content.extra.SHOW_FILESIZE", true);
startActivityForResult(intent, OPEN_DOCUMENT_TREE_REQUEST_CODE);
This does not show the usb stick neither was I able to filter the files and folders.
Same device: es-datei explorer is able to display the usb device.
My requirements are to display a custom file chooser where the user can select files from a customer specific cloud, internal storage or usb devices similar to the es datei explorer.
My solution with searching if the path: "mnt/usb_storage/*" exists works as required I am just wondering if there is a better way.