Sto usando questo codice per salvare bitmap in External Storage, ma non crea la cartella se non esiste:Salva bitmap in Android come JPEG External Storage in una cartella
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;
}
Come posso salvare il l'immagine nella nuova directory se non esiste e salva il valore predefinito se la cartella è presente nel dispositivo?
file.getParentFile(). Mkdirs() – njzk2
vedere come farlo in AsyncTask http://stackoverflow.com/a/29795857/3496570 – Nepster