Reputation: 69
I have looked at all of the questions related to saving a file in the external storage.
Links:
I even copied the entire method for the same but still cannot get the same result. Here is the log I am getting for the same:
W/System.err: java.io.IOException: No such file or directory
W/System.err: at java.io.UnixFileSystem.createFileExclusively0(Native Method)
code:
public void saveImageBitmap(Bitmap image_bitmap, String image_name) {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root, "/memories");
if (!myDir.exists()) {
myDir.mkdirs();
}
String fname = "Image-" + image_name + ".jpg";
File file = new File(myDir, fname);
Log.d(TAG, "File file: " + file);
if (file.exists()) {
file.delete();
}
try {
file.createNewFile(); // if file already exists will do nothing
FileOutputStream out = new FileOutputStream(file);
image_bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
MediaScannerConnection.scanFile(context, new String[]{file.toString()}, new String[]{file.getName()}, null);
}
Upvotes: 0
Views: 737
Reputation: 292
there are a few changes with storing data to media folder since android 10 (Q).the easiest way is to add android:requestLegacyExternalStorage="true"
in the manifest under application, but it is more like a work around.
search for "store image android 10" here and you find the right way for you.
Upvotes: 2