contentValues) ?: return openOutputStream(uri).use { bitmap.compress(Bitmap.CompressFormat.JPEG, 100, it) } contentValues.put(MediaStore.MediaColumns.IS_PENDING, 0) update(uri, contentValues, null, null) } Android 10 or higher https://github.com/umechanhika/playground/blob/master/android/AddScreenshotToGallery/app/ src/main/java/com/example/addscreenshottogallery/ui/util/ScreenshotUtil.kt