Turning a string into a Uri in Android


Question

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

How can I convert songchoice to the Uri?

1
205
1/20/2019 11:28:16 PM

Accepted Answer

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

471
6/28/2013 6:40:31 PM

Uri.parse(STRING);

See doc:

String: an RFC 2396-compliant, encoded URI

Url must be canonicalized before using, like this:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon