0

我想使用该路径将该视频复制到另一个目录,但引发我的错误说我的 URI 或路径不存在。

   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())
            }
        }
    })

这是我的错误:源'/storage/emulated/0/content:/com.android.externalstorage.documents/document/primary%3ADCIM%2FHDCamera%2FVID_20190903_114707.mp4'不存在

4

1 回答 1

0

如何使用其 Uri 在 Android Studio 中获取我由 Intent 选择的一个视频的路径?

你没有。

用户不必选择文件系统上的文件。用户可以选择云存储、文件服务器等中的内容。

即使用户确实选择了一些本地内容,您也可能无法访问它。在 Android 10+ 上,您几乎没有文件系统访问权限。而且,即使在 Android 9 和更早的设备上,用户也可以选择:

  • 另一个应用程序的内部存储上的本地文件
  • 可移动存储上的本地文件
  • 已加密且需要即时解密的本地文件
  • BLOB保存在数据库列中的字节流
  • 需要先被其他app下载的一段内容
  • ...等等

您无权通过文件系统访问任何内容。

我想使用该路径将该视频复制到另一个目录

最好不要那样做。除了源位置的问题之外,您在 Android 10 上也无法访问您的目的地。

如果您将目的地切换到您可以使用的某个位置,您可以InputStream通过调用openInputStream()aContentResolver并传入Uri您获得的

于 2019-09-03T22:10:37.503 回答