Tôi đang sử dụng mã này để lưu Bitmap trong lưu trữ bên ngoài nhưng nó không tạo ra các thư mục nếu nó không tồn tại:Lưu Bitmap trong Android như JPEG trong Bộ nhớ ngoài trong một thư mục
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;
}
Làm thế nào tôi có thể lưu hình ảnh trong thư mục mới nếu không tồn tại và lưu mặc định nếu thư mục có trong thiết bị?
file.getParentFile(). Mkdirs() – njzk2
thấy làm thế nào để làm điều đó trong AsyncTask http://stackoverflow.com/a/29795857/3496570 – Nepster