I am trying to create a directory in android for storing images taken by the camera app.
I have included the permission in the manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
</uses-permission>
I have also followed the answers given here :
Android mkdirs() sdcard do not work
File mkdirs() method not working in android/java
Android mkdir not making folder
Android failed to mkdir() on SD card
and a few others and all contain similar answers
This is what I have written
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
Log.i(TAG, "Storage Location read write permission available");
String root = Environment.getExternalStorageDirectory().toString();
File imagesFolder = new File(root + "/ImgDir");
if(imagesFolder.mkdirs()){
Log.i(TAG, "Storage Location is ready");
}else{
Log.i(TAG, "Storage Location is not ready");
}
}
else{
Log.i(TAG, "Storage Location read write permission not available");
}
The logcat shows "Storage Location is not ready". Can anyone tell me why the directory is not being created.
If the directory already exists then the application saves the image taken by the camera to the directory, but if it does not exist then the directory is not being created.
I am new to android, is there anything else that I am missing?
I am also getting false for all 4 of these lines :
Environment.getExternalStorageDirectory().canRead()
Environment.getExternalStorageDirectory().canWrite()
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).canRead()
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).canWrite()