Android - How to get two or more SD Cards' path from Card Reader using OTG to connect our phone?

391 views Asked by At

Hi everybody~~ I want my app to detect USB device(EX: flash, card reader) plugin and plug out. And also can get all SD Cards' paths which are plugin in my card reader. How can I get them??

I have already try to use BroadcastReceiver to catch Intent.ACTION_MEDIA_MOUNTED, Intent.ACTION_MEDIA_UNMOUNTED events, and also use intent.getData().toString() to get path, but if I use card reader, and plugin two SD Cards, this method will only get one path. But I want both of them!! How can I get them??

1

There are 1 answers

0
Skaard-Solo On

Well,

When you've got the path of the USB device, try

File usbPath = new File("path_to_usb_device");
File[] sdcardsPath = usbPath.listFiles();
for(File ff : sdcardsPath)
{
    Log.d("File repo", ff.getAbsolutePath());
}