I'm trying to pick video from gallery and want to get it's real path. But in the code it's showing Mediastore.Video.Media.DATA id deprecated in API Level 29. So please help me to find out the solution.
Here is my Video Picker Code:
val i = Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI)
startActivityForResult(i, videoCode)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == videoCode && resultCode == RESULT_OK) {
videoPath = getPathFromUri(data!!.data)
}
}
private fun getPathFromUri(uri: Uri?): String? {
var path:String?=null
val projection = arrayOf(MediaStore.Video.Media.DATA)
val cursor = contentResolver.query(uri!!, projection, null, null, null)
if (cursor != null) {
val columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)
cursor.moveToFirst()
path=cursor.getString(columnIndex)
}
cursor?.close()
return path
}