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

六月ゝ 毕业季﹏ 提交于 2019-12-11 11:44:58

问题


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.


回答1:


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.




回答2:


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/...



来源:https://stackoverflow.com/questions/30297714/how-to-get-the-file-path-from-a-device-acting-as-a-usb-mass-storage-in-android

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