访问External sdcard

来源:互联网 发布:2016年要死多少淘宝店 编辑:程序博客网 时间:2024/05/21 10:11

  1. 如何访问:  http://sigidin.blogspot.com/2011/08/check-external-sd-card-on-android.html
  2. external sdcard产生的背景和相关的问题:http://android.stackexchange.com/questions/33182/why-is-the-sd-card-mounted-to-sdcard-external-sd-instead-of-sdcard-or-m
  3. 访问的代码:
  4.     /**     * 获取外部Sdcard的路径     */    public static File getExternalSdcardPath(){        String[]  externalSdacardPath = {                "/mnt/external",                "/mnt/extSdCard",                "/mnt/sdcard/ext_sd",                "/mnt/sdcard/external_sd",                "/storage/extSdCard"        };        try{            StringBuilder sb = new StringBuilder();            try {                // Open the file                FileInputStream fs = new FileInputStream("/proc/mounts");                DataInputStream in = new DataInputStream(fs);                BufferedReader br = new BufferedReader(new InputStreamReader(in));                String strLine;                //Read File Line By Line                while ((strLine = br.readLine()) != null)   {                    // Remember each line                    sb.append(strLine);                }                //Close the stream                in.close();            } catch (Exception e) {                //Catch exception if any                e.printStackTrace();            }            for (String extSdcardPath : externalSdacardPath) {                if (sb.indexOf(extSdcardPath) > 0) {                    return new File(extSdcardPath);                }            }        }catch (Exception e){            e.printStackTrace();        }        return null;    }


原创粉丝点击