android get all external storage path for all devices

how to get internal and external storage path android
android read file from internal storage
android external storage path
how to access internal storage android programmatically
android internal storage path
getexternalfilesdir
android:requestlegacyexternalstorage
how to get list of video files in a specific folder in android

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

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

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<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;
    }

How can I get the list of mounted external storage of android device , To get all available external storage folders (including SD cards), you can use this How to get a path like "/mnt/sdcard/external_sd" (it may differ from device to​  I need to read image from an external usb storage on an Asus Tinkerboard. I tried to get the name of an external usb storage with the following get_device_list to extract the name. (manager.getdevices.). I get the name in the nom_cle_usb string, it's seems to be ok: /dev/bus/usb/003/009/

External directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

if you User data directory...

Environment.getDataDirectory()

Recommended reading : Android External Storage

Cheers!

Storage updates in Android 11, If your app opts out of scoped storage when running on Android 10 devices, On Android 11, apps cannot create their own app-specific directory on external storage. They can get the all files access permission by doing the following: these additional files and directories using either the MediaStore API or file paths. Environment.getExternalStorageState() if you don't have an SD card, you use: Environment.getDataDirectory() if there is no SD card, you can create your own directory on the device locally.

try this code to get all external storage path for all devices

File[] f = ContextCompat.getExternalFilesDirs(getApplicationContext(),null);
for (int i=0;i< f.length;i++)
{
  String path = f[i].getParent().replace("/Android/data/","").replace(getPackageName(),"");
  Log.d("DIRS",path); //sdcard and internal and usb
}

Data and file storage overview, Categories of storage locations; Permissions and access to external storage However, internal storage is always available on all devices, making it a more reliable place to put Android represents these devices using a path, such as /​sdcard . It's expensive for the system to open a file and to read a file for the first time. Starting in Android 4.1, read access is protected with the READ_EXTERNAL_STORAGE permission. Starting in Android 4.4, the owner, group and modes of files on external storage devices are now synthesized based on directory structure. This enables apps to manage their package-specific directories on external storage without requiring they hold the

Storing Files in Internal & External Storage, Every Android-compatible device supports a shared "external storage" that you can use to getExternalStorageDirectory(); // getting phone SD card path String​  However, internal storage is always available on all devices, making it a more reliable place to put data on which your app depends. Removable volumes, such as an SD card, appear in the file system as part of external storage. Android represents these devices using a path, such as /sdcard.

Android External Storage - Read, Write, Save File, Android External Storage, android save file to external storage, android read All applications can read and write files placed on the external storage and Also, external storage may be tied up by the user having mounted it as a USB storage device. Once the app is uninstalled, any data stored in this folder is gone too. Below Android 5.0 there is no reliable method to determine the path to a removable sd card. It differs from device to device and sometimes it is impossible. For above you should try getExternalFilesDirs (). It will give you two paths.

Android external storage path, 0 permissions. how to get the external sd card path on android. I want to show all root directory path of my android device from external and internal memory. Environment.getExternalStorageDirectory() returns top-level directory of the primary external storage. If device has multiple external storage directories, returned directory represents the primary external storage that the user will interact with. There is also APIs available for accessing secondary storage or getting external storage directories list.

Comments
  • Below Android 5.0 there is no reliable method to determine the path to a removable sd card. It differs from device to device and sometimes it is impossible. For above you should try getExternalFilesDirs(). It will give you two paths. The second one is on the card.
  • By the way: You picture is wrong. getExternalStorageDirectory does not deliver 'SD card' but 'Phone storage'.
  • So i realise that i read your post wrong from the beginning. I was confused as mostly the question is how to get the path to the sd card. But what you say is impossible. getExternalStorageDirectory() will deliver a path to Phone storage. Often that is /storage/emulated/0 or /mnt/sdcard or /sdcard. Please tell what you get.
  • @greenapps thank you for comment, i need create folder (mkdir) into sdcard, but if sdcard no space for save filem so create folder to another storage (phone storage) for save file.
  • That works for all api's and all devices. And exists always. It never is unmounted. And it always delivers external memory. And never a path to SD card. Except for old devices with Android 2.0 and 3.0. There it delivers indeed sometimes a path to a removable SD card. (I still have two such devices).
  • this method is fix on all device and API? (samsung,sony,huawei, etc...) ??
  • sdCard and externalSdCard and SECONDARY_STORAGE names is fixed and constant in all devies? for example: sdCard string fixed in huawei samsung sony ? or may Different example sd_card ?
  • SECONDARY_STORAGE is system variable and it is constant
  • getExternalStorageDirectory() is work for all devices and API and exists always? (if mounted) (example android 6+)
  • in my screenshot Phone storage is external or internal? (I do not want remove files after unistall app !!!)
  • @grizzly, That depends. In some android devices, you won't be able to insert your SD card (External Storage), where phone storage is the only storage and act as external devices (preferrably devices with 8gb or more internal storage).. you need to use your code to distinguish whether you have external storage and if so, what are you going to do, if not, what path will you take..
  • ok, In your opinion, @Fedor Kazakov answer is true and fix for all devices?
  • In my opinion, this answer is true and fix your SD card less or available problem.. stackoverflow.com/a/21724952/5876080 and Environment comes with OS. It's same across devices. @grizzly