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

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

    System.getenv("SECONDARY_STORAGE") returns null for Marshmallow. This is another way of finding all the externals dirs. You can check if it's removable which determines if internal/external

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        File[] externalCacheDirs = context.getExternalCacheDirs();
        for (File file : externalCacheDirs) {
            if (Environment.isExternalStorageRemovable(file)) {
                // It's a removable storage
            }
        }
    }
    

提交回复
热议问题