- 如何访问: 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
最新推荐文章于 2024-01-05 00:31:58 发布
本文提供了一种在Android设备上获取外部SD卡路径的方法。通过读取“/proc/mounts”文件来检查常见的外部SD卡挂载点,如“/mnt/external”、“/mnt/extSdCard”等。
摘要由CSDN通过智能技术生成