android 获取内置存储卡和外置存储卡

来源:互联网 发布:js改变button标签文字 编辑:程序博客网 时间:2024/06/10 19:04

本博客所讲的获取内置存储卡和外置存储卡的方式只适用于在/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 devicedev_mount sdcard /storage/sdcard0 emmc@fat /devices/platform/goldfish_mmc.0 /devices/platform/mtk-msdc.0/mmc_hostdev_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_hostdev_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]);///根路径}}}}


0 0
原创粉丝点击