Java 在 Android 中将字符串转换为 Uri

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2709087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 11:06:19  来源:igfitidea点击:

Turning a string into a Uri in Android

javaandroiduri

提问by James Rattray

I have a string, 'songchoice'. I want it to become a 'Uri' so I can use with MediaPlayer.create(context, Uri)

我有一个字符串,'songchoice'。我希望它成为一个“Uri”,这样我就可以使用MediaPlayer.create(context, Uri)

How can I convert songchoice to the Uri?

如何将 Songchoice 转换为 Uri?

回答by Anton Savenok

Uri.parse(STRING);

See doc:

见文档:

String: an RFC 2396-compliant, encoded URI

字符串:符合 RFC 2396 的编码 URI

Url must be canonicalized before using, like this:

Url 必须在使用前规范化,如下所示:

Uri.parse(Uri.decode(STRING));