简体   繁体   English

将 android.net.Uri 转换为 java.net.uri

[英]convert android.net.Uri to java.net.uri

i'm following along this answer: Android- how can I convert android.net.Uri object to java.net.URI object?我正在关注这个答案: Android-如何将 android.net.Uri 对象转换为 java.net.URI 对象?

android.net.Uri INPUT_FILE;
java.net.URI juri = new java.net.URI(INPUT_FILE.toString());
File inputFile = new File(juri);

I get this error;我收到这个错误; java.lang.IllegalArgumentException: URI scheme is not "file" java.lang.IllegalArgumentException:URI 方案不是“文件”

The file is an mp4 inside the android Downloads directory.该文件是 android 下载目录中的 mp4。 I'm currently using pixel 2 api 29. Any recommendations on how to fix the problem.我目前正在使用像素 2 api 29。有关如何解决问题的任何建议。

The problem you have is that a File must be a file on disk.您遇到的问题是 File 必须是磁盘上的文件。 That means the URI must start with file:/// Your URI doesn't.这意味着 URI 必须以 file:/// 开头,而您的 URI 则不是。 Either your URI is malformed, or it isn't to a local file.您的 URI 格式不正确,或者不是本地文件。 Either of those would need to be fixed.其中任何一个都需要修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM