Cannot retrieve image Uri shared from Gallery (Xiaomi)
I am trying to retrieve an image Uri shared from a Gallery app by intent to show it in my application. But it doesn't work on Xiaomi API 33. (It works fine on my other devices: Pixel API 35, Huawei API 29).
This is my code:
fun resolveUri(intentUri: Uri) {
val projection = arrayOf(MediaStore.Images.Media._ID)
contentResolver.query(
intentUri,
projection,
null,
null,
"${MediaStore.Images.Media.DATE_ADDED} DESC"
)?.use { cursor ->
val idColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID)
while (cursor.moveToNext()) {
val imageUri: Uri = Uri.withAppendedPath(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
cursor.getString(idColumn)
)
Log.d("TAG", "imageUri: $imageUri")
}
}
}
in result I am getting something like: photoUri: content://media/external/images/media/31
.
The ID seems to be random and increased every time I am trying to share the same photo.
Source: View source