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
Turning a string into a Uri in Android
提问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 James Rattray
Uri myUri = Uri.parse("http://www.google.com");
Here's the doc http://developer.android.com/reference/android/net/Uri.html#parse%28java.lang.String%29
这是文档http://developer.android.com/reference/android/net/Uri.html#parse%28java.lang.String%29
回答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));