android get all external storage path for all devices

后端 未结 3 1528
后悔当初
后悔当初 2021-01-06 19:34

getExternalStorageDirectory() return SD card path on my phone. (Huawei Y320 - android 4.2.2).

now, how to get path Pho

3条回答
  •  生来不讨喜
    2021-01-06 20:23

    I'm using this method:

        public static final String SD_CARD = "sdCard";
        public static final String EXTERNAL_SD_CARD = "externalSdCard";
        private static final String ENV_SECONDARY_STORAGE = "SECONDARY_STORAGE";
    
        public static Map getAllStorageLocations() {
            Map storageLocations = new HashMap<>(10);
            File sdCard = Environment.getExternalStorageDirectory();
            storageLocations.put(SD_CARD, sdCard);
            final String rawSecondaryStorage = System.getenv(ENV_SECONDARY_STORAGE);
            if (!TextUtils.isEmpty(rawSecondaryStorage)) {
                String[] externalCards = rawSecondaryStorage.split(":");
                for (int i = 0; i < externalCards.length; i++) {
                    String path = externalCards[i];
                    storageLocations.put(EXTERNAL_SD_CARD + String.format(i == 0 ? "" : "_%d", i), new File(path));
                }
            }
            return storageLocations;
        }
    

提交回复
热议问题