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

前端 未结 26 3201
清歌不尽
清歌不尽 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:48

    //manifest file outside the application tag
    //please give permission write this 
    //
            File file = new File("/mnt");
            String[] fileNameList = file.list(); //file names list inside the mnr folder
            String all_names = ""; //for the log information
            String foundedFullNameOfExtCard = ""; // full name of ext card will come here
            boolean isExtCardFounded = false;
            for (String name : fileNameList) {
                if (!isExtCardFounded) {
                    isExtCardFounded = name.contains("ext");
                    foundedFullNameOfExtCard = name;
                }
                all_names += name + "\n"; // for log
            }
            Log.d("dialog", all_names + foundedFullNameOfExtCard);
    

提交回复
热议问题