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

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

    I was using Dmitriy Lozenko's solution until i checked on an Asus Zenfone2, Marshmallow 6.0.1 and the solution is not working. The solution failed when getting EMULATED_STORAGE_TARGET, specifically for microSD path, i.e: /storage/F99C-10F4/. I edited the code to get the emulated root paths directly from emulated application paths with context.getExternalFilesDirs(null); and add more known phone-model-specific physical paths.

    To make our life easier, I made a library here. You can use it via gradle, maven, sbt, and leiningen build system.

    If you like the old-fashioned way, you can also copy paste the file directly from here, but you will not know if there is an update in the future without checking it manually.

    If you have any question or suggestion, please let me know

提交回复
热议问题