When my app first starts, it lets the user select a profile picture. This can be done taking a photo at the moment, or selecting it from the gallery.
After the user
After trying several things, this is what finally has worked for me:
ContextWrapper cw = new ContextWrapper(getApplicationContext());
File directory = cw.getDir("profile", Context.MODE_PRIVATE);
if (!directory.exists()) {
directory.mkdir();
}
File mypath = new File(directory, "thumbnail.png");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
resizedbitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
} catch (Exception e) {
Log.e("SAVE_IMAGE", e.getMessage(), e);
}
Basically the thing is to check if the directory (not the file) exists, and if not, create it with mkdir().