Reputation: 4162
I'm using intent to select a video,
fun openVideo(view: View) {
val intent = Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI)
intent.type = "video/*"
startActivityForResult(
Intent.createChooser(intent, "Select Video"),
REQUEST_TAKE_GALLERY_VIDEO
)
}
then i'm getting uri and path
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_TAKE_GALLERY_VIDEO && data != null) {
val videPath = data.data?.path
val selectedVideoUri: Uri? = data!!.data.toString()
}
}
output
videPath:
/external_files/KannadaGeeta/05CHAPTER2.mp3
selectedVideoUri :
content://com.mi.android.globalFileexplorer.myprovider/external_files/KannadaGeeta/05CHAPTER2.mp3
but I need path like below to check whether file exist or not
/storage/emulated/0/KannadaGeeta/13CHAPTER12.mp3
Look, by working on strings I can achieve what I want. But I'm looking for a proper way to get the video path.
Can anyone help me on this.
Edit:
i tried this which is giving false
File(selectedVideoUri).exists()
Upvotes: 0
Views: 906
Reputation: 4074
You can simply replace the /external_files
with the external directory.
val intentPath = activity?.intent!!.data!!.path!!
val absolutePath = Environment.getExternalStorageDirectory().toString() + intentPath.substringAfter("/external_files")
e.g
println("Intent Path : ${intentPath}")
// Intent Path : external_files/KannadaGeeta/05CHAPTER2.mp3
println("Absolute Path : ${absolutePath}")
// Absolute Path : /storage/emulated/0/KannadaGeeta/05CHAPTER2.mp3
Upvotes: 1