- 如何访问: http://sigidin.blogspot.com/2011/08/check-external-sd-card-on-android.html
- external sdcard产生的背景和相关的问题:http://android.stackexchange.com/questions/33182/why-is-the-sd-card-mounted-to-sdcard-external-sd-instead-of-sdcard-or-m
- 访问的代码:
/** * 获取外部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; }
访问External sdcard
最新推荐文章于 2021-05-06 17:39:09 发布