1

Hello I am trying to create a directory in the external storage but it is not working for me. I debugged the application there I find that code execute perfectly myDirectory.mkdirs(); but this does not create the directory when I see it using the SD card explorer

Any idea why it is not creating the PMS directory in the external storage ?

String capturedPhotoName = System.currentTimeMillis() + ".png";

try {
    File myDirectory = new File(Environment.getExternalStorageDirectory()+ "/PMS/");
    if(!myDirectory.exists()) {
        myDirectory.mkdirs();
    }
    File photo = new File(myDirectory, capturedPhotoName);
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);
    startActivityForResult(cameraIntent, CAMERA_INTENT_REQUEST);
} catch(Exception e) {
    Log.e("PMS", e.getMessage());
}
RenniePet
  • 11,420
  • 7
  • 80
  • 106
N Sharma
  • 33,489
  • 95
  • 256
  • 444

2 Answers2

0

Try this:

boolean success = (new File(getActivity().getApplicationContext().getFilesDir()+"/YourAppFolderName")).mkdir(); 
        if (!success){
            Log.w("directory not created", "directory not created");
        }

Also in the manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Skynet
  • 7,820
  • 5
  • 44
  • 80
0

Yeah really very silly mistake I made, forgot to add permission to write in the SD Card but it should have thrown the exception

Anyway, it solved my issue

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
N Sharma
  • 33,489
  • 95
  • 256
  • 444