我有一个字符串
如何将songchoice转换为Uri?
'songchoice'
,我想让它变成一个“Uri”,这样我就可以在MediaPlayer.create(context, Uri)
中使用了。如何将songchoice转换为Uri?
Uri myUri = Uri.parse("http://www.google.com");
这里是文档 http://developer.android.com/reference/android/net/Uri.html#parse%28java.lang.String%29
Uri.parse(STRING);
查看文档:
字符串:符合RFC 2396标准的编码URI
在使用之前必须将URL规范化,如下所示:
Uri.parse(Uri.decode(STRING));
我需要将一个本地文件路径转换为URI格式,但是没有file://
前缀。因此即使使用了new URI()
构造函数也无法正常工作。
Uri.parse(Uri.decode(STRING));
导致FileNotFoundException: No content provider
(参见此问题)。
我通过首先创建一个File
对象来获取有效的URI,即:
Uri myUri = Uri.fromFile(new File(STRING));