Alexandre Martin Alexandre Martin - 8 months ago 54
Android Question

How to create a new folder in android DCIM

I am actually able to capture a photo and to save it in android external storage DCIM folder.

My problem is that I can't create a new folder in it, so DCIM/MyPic.jpg became DCIM/MyFolder/MyPic.jpg.

Here is my source code :

File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "address");

if (!f.exists()) {

File file = new File(Environment.getExternalStorageDirectory()
+ File.separator
+ "DCIM"
+ File.separator
+ "address"
+ File.separator
, "IMG_001.jpg");

Notice that I correctly asked for WRITE_EXTERNAL_STORAGE permission in manifest.

The intent part to capture photo is fine, because I can save it directly to DCIM.

I do not get any error message, but nothing happens... no 'address' folder created :(

Thanks for help :D


As posted in the comments, I tried your code and it worked for me.

public class MainActivity extends Activity {

    private final static String TAG = MainActivity.class.getSimpleName();

    protected void onCreate(Bundle savedInstanceState) {

        final File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "address");

        if (!f.exists()) {
            Log.d(TAG, "Folder doesn't exist, creating it...");
            boolean rv = f.mkdir();
            Log.d(TAG, "Folder creation " + ( rv ? "success" : "failed"));
        } else {
            Log.d(TAG, "Folder already exists.");


<manifest xmlns:android=""

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


    <activity android:name=".MainActivity">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />


Before launching the app I have to enable the permission manually because I am on Android 6.

** Logs when launching the app the first time **

D/MainActivity: Folder doesn't exist, creating it...
D/MainActivity: Folder creation success

** Logs when launching the app the second time **

D/MainActivity: Folder already exists.