I am using an custom view and in that i am using an canvas in which a user can draw anything and after that i want to save that image in sd card bt was not able to do that.
I had this issue in the Emulator (Android 4.4) and turns out it's due to an Android bug, where it happens when the user hasn't taken a photo on the device before (i.e. gallery is empty and hasn't been initialized.). The workaround is to initialize the photo directory manually:
void fixMediaDir() {
File sdcard = Environment.getExternalStorageDirectory();
if (sdcard != null) {
File mediaDir = new File(sdcard, "DCIM/Camera");
if (!mediaDir.exists()) {
mediaDir.mkdirs();
}
}
}
Not sure if this is fixed in later versions of Android.