Reputation: 21
I want to use the path to copy that video to another directory but the error that throws me says my URI or path does not exist.
probar.setOnClickListener({
val selectedImageUri2=globalVariable.video//here I just saved the uri path of the intent
if(!CheckPermissionFromDevice()){
requestPermission()
} else {
val sourcePath = Environment.getExternalStorageDirectory().absolutePath +"/"+ selectedImageUri2.toString()
Toast.makeText(this, "SOURCE PATH:: "+sourcePath, Toast.LENGTH_SHORT).show()
println("SOURCE"+sourcePath)
val source= File(sourcePath)
val destinationPath = Environment.getExternalStorageDirectory().absolutePath + "/AudioFiscalia/"
val destination = File(destinationPath)
try {
FileUtils.copyFile(source, destination)
Toast.makeText(applicationContext, "TRY BIEN", Toast.LENGTH_LONG).show()
} catch (e: IOException) {
e.printStackTrace()
Toast.makeText(applicationContext, "CATCH"+e.toString(), Toast.LENGTH_LONG).show()
println("error"+e.toString())
}
}
})
This is my error: Source '/storage/emulated/0/content:/com.android.externalstorage.documents/document/primary%3ADCIM%2FHDCamera%2FVID_20190903_114707.mp4' does not exist
Upvotes: 0
Views: 284
Reputation: 1006964
How to get the path of one video that I picked by Intent in Android Studio using its Uri?
You don't.
The user does not have to choose a file on the filesystem. The user could choose content in cloud storage, on a file server, etc.
Even if the user does elect to choose some local content, you may not have access to it. On Android 10+, you have very little filesystem access. And, even on Android 9 and older devices, the user could choose:
BLOB
column in a databaseYou do not have access to any of that via the filesystem.
I want to use the path to copy that video to another directory
Preferably, do not do that. Beyond your problems with the source location, your destination is inaccessible to you on Android 10.
If you switch your destination to some location that you can use, you can get an InputStream
on the source by calling openInputStream()
on a ContentResolver
, passing in the Uri
that you got.
Upvotes: 0