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

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

    The following steps worked for me. You just need to write this lines:

    String sdf = new String(Environment.getExternalStorageDirectory().getName());
    String sddir = new String(Environment.getExternalStorageDirectory().getPath().replace(sdf,""));
    

    The first line will give the name of sd directory, and you just need to use it in the replace method for the second string. The second string will contain the path for the internal and removable sd(/storage/ in my case). I just needed this path for my app but you can go further if you need it.

提交回复
热议问题