How can I get the external SD card path for Android 4.0+?

前端 未结 26 3196
清歌不尽
清歌不尽 2020-11-22 04:48

Samsung Galaxy S3 has an external SD card slot, which is mounted to /mnt/extSdCard.

How can I get this path by something like Environment.getExter

26条回答
  •  执笔经年
    2020-11-22 05:44

           File[] files = null;
        File file = new File("/storage");// /storage/emulated
    if (file.exists()) {
            files = file.listFiles();
                }
                if (null != files)
                    for (int j = 0; j < files.length; j++) {
                        Log.e(TAG, "" + files[j]);
                        Log.e(TAG, "//--//--// " +             files[j].exists());
    
                        if (files[j].toString().replaceAll("_", "")
                                .toLowerCase().contains("extsdcard")) {
                            external_path = files[j].toString();
                            break;
                        } else if (files[j].toString().replaceAll("_", "")
                                .toLowerCase()
                                .contains("sdcard".concat(Integer.toString(j)))) {
                            // external_path = files[j].toString();
                        }
                        Log.e(TAG, "--///--///--  " + external_path);
                    }
    

提交回复
热议问题