Make directory in android

Update: Since Android 10,11 Storage updates, Google has restricted Storage access through standard programming language file operations.

For applications targeting only Android 10 (API 29) and above, you need to declare "requestLegacyExternalStorage="true" " in your android manifest file to use programming language based file operations.

<application android:requestLegacyExternalStorage="true" ....>

==========

You want to be sure you are correctly finding the address of your SDCard, you can't be sure its always at any particular address. You will want to do the following!

File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"images");
directory.mkdirs();

Let me know if this works for you!

You will also need the following line in your AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


I use this to know the result:

File yourAppDir = new File(Environment.getExternalStorageDirectory()+File.separator+"yourAppDir");

    if(!yourAppDir.exists() && !yourAppDir.isDirectory()) 
    {
        // create empty directory
        if (yourAppDir.mkdirs())
        {
            Log.i("CreateDir","App dir created");
        }
        else
        {
            Log.w("CreateDir","Unable to create app dir!");
        }
    }
    else
    {
        Log.i("CreateDir","App dir already exists");
    }

you can use this :

File directory = new File(Environment.getExternalStorageDirectory() + "/images");
directory.mkdirs();

Tags:

Java

Android