How to Create a Folder in Android External Storage Directory

how to create a folder in android External Storage Directory?

Do it like this :

String folder_main = "NewFolder";

File f = new File(Environment.getExternalStorageDirectory(), folder_main);
if (!f.exists()) {
f.mkdirs();
}

If you wanna create another folder into that :

File f1 = new File(Environment.getExternalStorageDirectory() + "/" + folder_main, "product1");
if (!f1.exists()) {
f1.mkdirs();
}

Android 11 doesn't create app directory on external storage

Ok, I found a way to do it. Our app cannot create that folder but if we call for example getApplicationContext().getExternalFilesDir(""); Android will create that folder for us.

Quite stupid that if we want open dir which doesn't exist it will create it but when we want create it by ourself there is a problem. Android devs should makes our life easier but they making it more difficult with every update.

Android 11 - Creating app-specific directory on external storage

They are referring to creating arbitrary directories off of the external storage root (e.g., Environment.getExternalStorageDirectory().

getExternalFilesDir() and similar methods on Context are fine solutions to use instead!



Related Topics



Leave a reply



Submit