Android Scope Storage: Get File Uri

January 14, 2020
val idIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns._ID)
val id = cursor.getLong(idIndex)

var uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    // https://developer.android.com/reference/kotlin/android/provider/MediaStore#setrequireoriginal
    uri = MediaStore.setRequireOriginal(uri)
}
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.