Turning a string into a Uri in Android Turning a string into a Uri in Android android android

Turning a string into a Uri in Android


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));


The String I had to convert to a URI was a local file path, but without the file:// prefix. So even

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

resulted in FileNotFoundException: No content provider (see also this question).I got a valid URI by first creating a File object i.e.:

Uri myUri = Uri.fromFile(new File(STRING));