I'm trying to save a bitmap to external storage. I have used the code that I have found in android - save image into gallery. However, the resulting file is 0 B in size but do contain thumbnail. My code is:
private fun saveBitmap(bitmap: Bitmap, name: String) {
val contentValues = contentValuesOf(
MediaStore.MediaColumns.TITLE to name,
MediaStore.MediaColumns.DISPLAY_NAME to name,
MediaStore.MediaColumns.MIME_TYPE to "images/jpeg",
MediaStore.MediaColumns.DATE_ADDED to System.currentTimeMillis()
)
val resolver = contentResolver
val uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
val outputStream = resolver.openOutputStream(uri!!)!!
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, outputStream)
outputStream.flush()
outputStream.close()
}