I am using this code to save Bitmap in External Storage but it does not create the folder if it not exists:
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOutputStream = null;
File file = new File(path + "/Captures/", "screen.jpg");
try {
fOutputStream = new FileOutputStream(file);
capturedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOutputStream);
fOutputStream.flush();
fOutputStream.close();
MediaStore.Images.Media.insertImage(getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName());
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(this, "Save Failed", Toast.LENGTH_SHORT).show();
return;
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "Save Failed", Toast.LENGTH_SHORT).show();
return;
}
How can I save the image in the new directory if not exists and save default if the folder is there in the device?
try this it will gives u result sure:
add this one to show in gallery:
look at this link for clear answer: show folder images in gallery
You should take a look in the documentation of File, you'll find the method mkdir(). It is pretty much the same as the unix one : https://developer.android.com/reference/java/io/File.html#mkdir()
Please use the below code snippet might be help full
Use the following:
late but might be helpful to someone. use below code it will save the bitmap in external directory more faster because of BufferOutPutStream.