Unable to create a new directory in Android external storage for some reason, Im assuming there is something im missing but not able to spot it below is my code which I am using to attempt to create the directory, any help will go a long way thanks
Calendar calendarTime = Calendar.getInstance();
String newFolder = "/NewFolder/videos";
File newDirectory = new File(Environment
.getExternalStorageDirectory().toString() + newFolder);
newDirectory.mkdir();
File file = new File(newDirectory,
String.valueOf(calendarTime.getTimeInMillis()) + ".mp4");
if (camcorderProfile.fileFormat == MediaRecorder.OutputFormat.THREE_GPP) {
recorder.setOutputFile(file.getAbsolutePath());
} else if (camcorderProfile.fileFormat == MediaRecorder.OutputFormat.MPEG_4) {
recorder.setOutputFile(file.getAbsolutePath());
} else {
recorder.setOutputFile(file.getAbsolutePath());
}
and in my manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
File.mkdir() will only create the directory if its parent exists. In this case, the directory you want to create is "videos" and its parent is "NewFolder". "videos" will not be created if "NewFolder" does not exist. If you want to create both directories at once, you should use File.mkdirs() instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With