简体   繁体   English

Android上的外部USB存储

[英]External USB storage on Android

I'm writing small media player for Android on DigiBoard(Evaluation Board). 我正在DigiBoard(评估板)上为Android编写小型媒体播放器。 I want to use USB storage for playing music. 我想使用USB存储设备播放音乐。 I can plug USB, my board mount it(I see a notification) and when I use ADB shell and go to /mnt/ i have several folders, one of them is udisk and SD Card: 我可以插入USB,将其安装在板上(我会看到通知),当我使用ADB Shell并转到/ mnt /时,我有几个文件夹,其中一个是udisk和SD卡:

# cd mnt
cd mnt
# ls
ls
obb
shm
asec
extsd
udisk
sdcard
secure

I'm listing a proc/mounts content: 我列出了proc / mounts内容:

# cat mounts
cat mounts
rootfs / rootfs rw 0 0
ubi0_0 / ubifs rw,relatime 0 0
tmpfs /dev tmpfs rw,relatime,mode=755 0 0
devpts /dev/pts devpts rw,relatime,mode=600 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,relatime 0 0
tmpfs /mnt/asec tmpfs rw,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/shm tmpfs rw,relatime,size=1024k,mode=775,uid=1000,gid=1003 0 0
/dev/block/vold/179:1 /mnt/sdcard vfat ro,dirsync,nosuid,nodev,noexec,relatime,u
id=1000,gid=1015,fmask=0002,dmask=0002,allow_utime=0020,codepage=cp437,iocharset
=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/block/vold/179:1 /mnt/secure/asec vfat ro,dirsync,nosuid,nodev,noexec,relat
ime,uid=1000,gid=1015,fmask=0002,dmask=0002,allow_utime=0020,codepage=cp437,ioch
arset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
tmpfs /mnt/sdcard/.android_secure tmpfs ro,relatime,size=0k,mode=000 0 0
/dev/block/vold/8:1 /mnt/udisk vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=
1000,gid=1015,fmask=0002,dmask=0002,allow_utime=0020,codepage=cp437,iocharset=is
o8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
#

I have here some paths, two of them are "valid" mnt/sdcard and mnt/udisk. 我这里有一些路径,其中两个是“有效”的mnt / sdcard和mnt / udisk。 I've read that entries with vfat are valid mounts, but /mnt/secure/asec have vfat property. 我读过带有vfat的条目是有效的装载,但是/ mnt / secure / asec具有vfat属性。 I have application named ES File Explorer and I can see files in "udisk" folder: 我有一个名为ES File Explorer的应用程序,可以在“ udisk”文件夹中看到文件: EZ输出 so it is possible to filter mounted sources. 因此可以过滤安装的源。 Can you tell me how to filter this? 你能告诉我如何过滤吗? Are some folders in /mnt by default and i can list them/hardcode in app so I'll check their names? 默认情况下,/ mnt中是否有一些文件夹,我可以在应用程序中列出它们/硬代码,以便检查其名称?

OK, I've done it on my own. 好的,我自己完成了。 You need to read /proc/mounts file and filter its content: 您需要读取/proc/mounts文件并过滤其内容:

if (entry.contains("vfat") && !entry.contains("secure")) {
    String absolutePath = entry.split(" ")[1];
}

entry is a single line form that file. 条目是该文件的单行形式。 In absolutePath you have direct path to mounted device like /mnt/sdcard or /mnt/udisk. 在absolutePath中,您可以直接访问已挂载的设备,例如/ mnt / sdcard或/ mnt / udisk。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM