usb_storage一般是外置SD卡的路径,通过OTG连U盘几乎都是从usbhost0开始计数的,不过偶尔也有例外!
可以用记事本打开"system/etc/vold.fstab"这个文件,里面记录了外接设备的名称,识别方法自己百度或者调试!

解决方案 »

  1.   

    public class Dev_MountInfo implements IDev {  
    /*
        #######################
        ## 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
        ######################
        */
        public final String HEAD = "dev_mount";  
        private final int DEV_INTERNAL = 0;
        private final int DEV_EXTERNAL = 1;
        private final int DEV_USB = 2;//这个可能没有,上面两个一般都会有
      
        private ArrayList<String> cache = new ArrayList<String>();  
      
        private static Dev_MountInfo dev;  
        private DevInfo info;  
        private final File VOLD_FSTAB = new File(
        Environment.getRootDirectory().getAbsoluteFile()
                + File.separator + "etc"
                + File.separator + "vold.fstab");
        public static Dev_MountInfo getInstance() {  
            if (null == dev)  
                dev = new Dev_MountInfo();  
            return dev;  
        }  
        private DevInfo getInfo(final int device) {  
            try {  
                initVoldFstabToCache();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
      
            info = new DevInfo();
            if(device < cache.size()){
            String[] sinfo = cache.get(device).split(" |\t");
            if(sinfo.length >= 5){
            info.setLabel(sinfo[1]);
            info.setMount_point(sinfo[2]);
            info.setPart(sinfo[3]);
            info.setSysfs_path(sinfo[4]);
            }
            }
            return info;  
        }  
        /** 
         * init the words into the cache array 
         * @throws IOException 
         */  
        private void initVoldFstabToCache() throws IOException {  
            cache.clear();  
            BufferedReader br = new BufferedReader(new FileReader(VOLD_FSTAB));
            String tmp = null;  
            while ((tmp = br.readLine()) != null) {  
                // the words startsWith "dev_mount" are the SD info  
                if (tmp.startsWith(HEAD)) {  
                    cache.add(tmp);  
                    Log.v("xcl", tmp);
                }  
            }  
            br.close();  
            cache.trimToSize();  
        }  
        public class DevInfo {  
            private String label, mount_point, part;
            private String sysfs_path;  
            public String getLabel() {  
                return label;  
            }  
      
            private void setLabel(String label) {  
                this.label = label;  
            }  
            public String getMount_point() {  
                return mount_point;  
            }  
      
            private void setMount_point(String mount_point) {  
                this.mount_point = mount_point;  
            }  
            public String getPart() {  
                return part;  
            }  
      
            private void setPart(String part) {  
                this.part = part;  
            }  
            public String getSysfs_path() {  
                return sysfs_path;  
            }  
      
            private void setSysfs_path(String sysfs_path) {  
                this.sysfs_path = sysfs_path;  
            }  
      
        }  
      
        public DevInfo getInternalInfo() {
            return getInfo(DEV_INTERNAL);
        }
      
        public DevInfo getExternalInfo() {
            return getInfo(DEV_EXTERNAL);
        }
        
        public DevInfo getUSBInfo(){
        return getInfo(DEV_USB);
        }
    }  
      
    interface IDev {  
        DevInfo getInternalInfo();  
      
        DevInfo getExternalInfo();  
    }  
    调用代码://获得各盘符路径
        Dev_MountInfo dev = Dev_MountInfo.getInstance();  
        DevInfo info = dev.getInternalInfo();
        this.diskInternal = info.getMount_point();
        //Environment.getExternalStorageDirectory() 这两个要是不一样咋办
        info = dev.getExternalInfo(); 
        this.diskExternal = info.getMount_point();
        info = dev.getUSBInfo(); 
        this.diskUSB = info.getMount_point();
    参考:http://blog.csdn.net/xubright/article/details/9832607
      

  2.   

    ## Vold 2.0 Generic fstab
    ## - San Mehat ([email protected])
    ## #######################
    ## 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 /mnt/sdcard auto /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
    #dev_mount flash /mnt/sdcard auto /devices/virtual/mtd/mtd9/mtdblock9dev_mount flash /mnt/sdcard auto /devices/virtual/mtd/mtd9/mtdblock9
    dev_mount sdcard /mnt/external_sd auto /devices/platform/rk29_sdmmc.0/mmc_host/mmc0
    dev_mount udisk /mnt/usb_storage auto /devices/platform/usb20_host/usb /devices/platform/usb20_otg/usb## Example of a dual card setup
    # dev_mount left_sdcard  /sdcard1  auto /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
    # dev_mount right_sdcard /sdcard2  auto /devices/platform/goldfish_mmc.1 /devices/platform/msm_sdcc.3/mmc_host/mmc1## Example of specifying a specific partition for mounts
    # dev_mount sdcard /sdcard 2 /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
    这个是我的平板的vold.fstab内容,好吧我记错了,/mnt/sdcard代表的内置ROM /mnt/usb_storage是OTG连接的路径 /mnt/external_sd是外置SD卡