From 47bfbb9b7c88932a5c2a68679c7068d5015f9f57 Mon Sep 17 00:00:00 2001 From: AdamGrzybkowski Date: Tue, 27 Aug 2024 13:49:32 +0200 Subject: [PATCH 1/2] Use file mode for the output image file --- .../src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java index c2f34d511..6f4122d91 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java @@ -40,6 +40,8 @@ public class BitmapCropTask extends AsyncTask { private static final String CONTENT_SCHEME = "content"; + private static final String WRITE_AND_TRUNCATE = "wt"; + private final WeakReference mContext; private Bitmap mViewBitmap; @@ -213,7 +215,7 @@ private void saveImage(@NonNull Bitmap croppedBitmap) { OutputStream outputStream = null; ByteArrayOutputStream outStream = null; try { - outputStream = context.getContentResolver().openOutputStream(mImageOutputUri); + outputStream = context.getContentResolver().openOutputStream(mImageOutputUri, WRITE_AND_TRUNCATE); outStream = new ByteArrayOutputStream(); croppedBitmap.compress(mCompressFormat, mCompressQuality, outStream); outputStream.write(outStream.toByteArray()); From a24b486a2135cd3908cc51e629c23ab87d4b7eb2 Mon Sep 17 00:00:00 2001 From: AdamGrzybkowski Date: Thu, 26 Sep 2024 12:42:16 +0200 Subject: [PATCH 2/2] Replace to rwt as per Google recommendation https://issuetracker.google.com/issues/180526528#comment3 --- .../src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java index 6f4122d91..73d9aff3a 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java @@ -40,7 +40,7 @@ public class BitmapCropTask extends AsyncTask { private static final String CONTENT_SCHEME = "content"; - private static final String WRITE_AND_TRUNCATE = "wt"; + private static final String READ_WRITE_AND_TRUNCATE = "rwt"; private final WeakReference mContext; @@ -215,7 +215,7 @@ private void saveImage(@NonNull Bitmap croppedBitmap) { OutputStream outputStream = null; ByteArrayOutputStream outStream = null; try { - outputStream = context.getContentResolver().openOutputStream(mImageOutputUri, WRITE_AND_TRUNCATE); + outputStream = context.getContentResolver().openOutputStream(mImageOutputUri, READ_WRITE_AND_TRUNCATE); outStream = new ByteArrayOutputStream(); croppedBitmap.compress(mCompressFormat, mCompressQuality, outStream); outputStream.write(outStream.toByteArray());