概述
本博客所讲的获取内置存储卡和外置存储卡的方式只适用于在/system/etc文件夹中有 vold.fstab文件的手机
,我的手机该文件内容如下:
## Vold 2.0 Generic fstab
## - San Mehat (san@android.com)
##
#######################
## Regular device mount
##
## Format: dev_mount <label> <mount_point> <part> <sysfs_path1...>
## label - Label for the volume
## mount_point - Where the volume will be mounted
## part - Partition # (1 based), or 'auto' for first usable partition.
## <sysfs_path> - List of sysfs paths to source devices
######################
## Example of a standard sdcard mount for the emulator / Dream
# Mounts the first usable partition of the specified device
dev_mount sdcard /storage/sdcard0 emmc@fat /devices/platform/goldfish_mmc.0 /devices/platform/mtk-msdc.0/mmc_host
dev_mount sdcard2 /storage/sdcard1 auto /devices/platform/goldfish_mmc.1 /devices/platform/mtk-msdc.1/mmc_host
## Example of a dual card setup
# dev_mount left_sdcard /mnt/sdcard1 auto /devices/platform/goldfish_mmc.0 /devices/platform/mtk-sd.0/mmc_host/mmc0
# dev_mount right_sdcard /mnt/sdcard2 auto /devices/platform/goldfish_mmc.1 /devices/platform/mtk-sd.2/mmc_host/mmc2
## Example of specifying a specific partition for mounts
# dev_mount sdcard /mnt/sdcard 2 /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
重要的是这两句话
dev_mount sdcard /storage/sdcard0 emmc@fat /devices/platform/goldfish_mmc.0 /devices/platform/mtk-msdc.0/mmc_host
dev_mount sdcard2 /storage/sdcard1 auto /devices/platform/goldfish_mmc.1 /devices/platform/mtk-msdc.1/mmc_host
这个emmc@fat表示的是存储卡的类型是内置的,auto指的是存储卡是外置的,
/storage/sdcard0
/storage/sdcard1
分别表示的是内置存储卡和外置存储卡的根路径,
下面我直接上代码了<span style="white-space:pre">
</span>
</pre><p><pre name="code" class="java"><span style="white-space:pre">
</span>br=new BufferedReader(new FileReader(new File("/system/etc/vold.fstab")));
StringBuilder sb=new StringBuilder("");
String line=null;
while((line=br.readLine())!=null){
String[]strtmp=line.split(" ");
if(strtmp.length>0){
if(strtmp[0].equals("dev_mount")){
if(strtmp[3].equals("emmc@fat")){
Log.e("emmc@fat", "内置存储卡");
menu.addSubMenu("内置存储卡");
filepath.add(strtmp[2]);//根路径
}else if(strtmp[3].equals("auto")){
Log.e("auto", "外置存储卡");
menu.addSubMenu("外置存储卡");
filepath.add(strtmp[2]);///根路径
}
}
}
}
最后
以上就是眼睛大信封为你收集整理的android 获取内置存储卡和外置存储卡的全部内容,希望文章能够帮你解决android 获取内置存储卡和外置存储卡所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复