user3201441
user3201441

Reputation: 167

How to get the file path from a device acting as a usb mass storage in android

I am trying to get filenames(and also the filepath), from a Garmin device which acts as a usb mass storage. Connecting the device to the computer, the filepath is G:\Garmin. Connecting that to the android tablet using OTG and Explorer(i have check the app setting - the package name is : com.android.rk), the filepath is USB/Garmin. Using ES File Explorer, I have seen that the file path is mnt/usb_storage/Garmin. So in the code, as I am trying to parse the system.xml from the file path usb_storage/Garmin, I have put the filepath like this:

String file = Environment.getExternalStorageDirectory() + "mnt/usb_storage/Garmin/system.xml";

When I run the app, it crashes, meaning that it cannot find the file system.xml. Is it right that I use Environment.getExternalStorageDirectory() when I'm looking for the file in a usb device connected via OTG? Can you please point me to what should be done? Thank you so much.

Upvotes: 1

Views: 3396

Answers (2)

greenapps
greenapps

Reputation: 11224

String file = Environment.getExternalStorageDirectory() + "mnt/usb_storage/Garmin/system.xml";

You mean:

String fileName = "/mnt/usb_storage/Garmin/system.xml";

That's all. Note tne /mnt/... so NOT mnt/...

Upvotes: 2

Phantômaxx
Phantômaxx

Reputation: 38098

By using Environment.getExternalStorageDirectory(), you are actually pointing your sd card or internal storage (depending on which is set as current) and under that you are looking for the device mount point.

But mount points in Unix are seen at the root level.
Therefore, try directly /mnt/usb_storage/Garmin/system.xml, instead.

Upvotes: 1

Related Questions