android获取所有设备的所有外部存储路径

android获取所有设备的所有外部存储路径

本文介绍了android获取所有设备的所有外部存储路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

getExternalStorageDirectory()返回我手机上的 SD卡路径. (华为Y320-android 4.2.2 ).

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

现在,如何获取所有设备和所有API的路径电话存储路径?在底部屏幕截图中抢劫.

now, how to get path Phone Storage path for all devices and all API? loot at bottom screenshot.

推荐答案

我正在使用此方法:

    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<String, File> getAllStorageLocations() {
        Map<String, File> 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;
    }

这篇关于android获取所有设备的所有外部存储路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 17:40