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.getExternalStorageDirec
late but might be helpful to someone. use below code it will save the bitmap in external directory more faster because of BufferOutPutStream.
public boolean storeImage(Bitmap imageData, String filename) {
// get path to external storage (SD card)
File sdIconStorageDir = null;
sdIconStorageDir = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/myAppDir/");
// create storage directories, if they don't exist
if (!sdIconStorageDir.exist()) {
sdIconStorageDir.mkdirs();
}
try {
String filePath = sdIconStorageDir.toString() + File.separator + filename;
FileOutputStream fileOutputStream = new FileOutputStream(filePath);
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
//Toast.makeText(m_cont, "Image Saved at----" + filePath, Toast.LENGTH_LONG).show();
// choose another format if PNG doesn't suit you
imageData.compress(Bitmap.CompressFormat.PNG, 100, bos);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
Log.w("TAG", "Error saving image file: " + e.getMessage());
return false;
} catch (IOException e) {
Log.w("TAG", "Error saving image file: " + e.getMessage());
return false;
}
return true;
}