I am using the following code to convert bitmap to Uri:
fun convertBitmapToUri(context: Context, bitmap: Bitmap): Uri {
val bytes = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes)
val path = MediaStore.Images.Media.insertImage(context.contentResolver, bitmap, "Title", null)
return Uri.parse(path)
}
This code works fine. But, after updating the sdk version to 29, insertImage
method is deprecated. And when I checked the doc, I saw this statement:
This method was deprecated in API level 29. inserting of images should be performed using MediaColumns#IS_PENDING, which offers richer control over lifecycle.
So, how can I convert bitmap to Uri using this MediaColumns#IS_PENDING
?