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

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

    Actually in some devices the external sdcard default name is showing as extSdCard and for other it is sdcard1.

    This code snippet helps to find out that exact path and helps to retrieve you the path of external device.

    String sdpath,sd1path,usbdiskpath,sd0path;    
            if(new File("/storage/extSdCard/").exists())
                {
                   sdpath="/storage/extSdCard/";
                   Log.i("Sd Cardext Path",sdpath);
                }
            if(new File("/storage/sdcard1/").exists())
             {
                  sd1path="/storage/sdcard1/";
                  Log.i("Sd Card1 Path",sd1path);
             }
            if(new File("/storage/usbcard1/").exists())
             {
                  usbdiskpath="/storage/usbcard1/";
                  Log.i("USB Path",usbdiskpath);
             }
            if(new File("/storage/sdcard0/").exists())
             {
                  sd0path="/storage/sdcard0/";
                  Log.i("Sd Card0 Path",sd0path);
             }
    

提交回复
热议问题