如何从充当USB大容量存储设备的设备中获取文件路径 [英] How to get the file path from a device acting as a usb mass storage in android
问题描述
我正在尝试从充当USB大容量存储设备的Garmin设备获取文件名(以及文件路径).将设备连接到计算机,文件路径为G:\ Garmin.使用OTG和Explorer将其连接到android平板电脑(我已经检查了应用程序设置-包名称为com.android.rk),文件路径为USB/Garmin.使用ES File Explorer,我已经看到文件路径是mnt/usb_storage/Garmin.因此,在代码中,当我尝试从文件路径usb_storage/Garmin解析system.xml时,我将文件路径设置如下:
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";
当我运行该应用程序时,它崩溃了,这意味着它找不到文件 system.xml .在通过OTG连接的USB设备中寻找文件时,我使用Environment.getExternalStorageDirectory()是否正确?您能指出我该怎么做吗?非常感谢.
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.
推荐答案
通过使用Environment.getExternalStorageDirectory()
,您实际上是指向sd卡或内部存储器(取决于哪个设置为当前),并在其下指向. strong>您正在寻找设备安装点.
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.
但是Unix中的挂载点是在根级别上看到的.
因此,请直接尝试/mnt/usb_storage/Garmin/system.xml
.
But mount points in Unix are seen at the root level.
Therefore, try directly /mnt/usb_storage/Garmin/system.xml
, instead.
这篇关于如何从充当USB大容量存储设备的设备中获取文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!