Convert String to Uri

Convert String to Uri

You can use the parse static method from Uri

//...
import android.net.Uri;
//...

Uri myUri = Uri.parse("http://stackoverflow.com")

Convert Uri to String and String to Uri

I need to know way for converting uri to string and string to uri.

Use toString() to convert a Uri to a String. Use Uri.parse() to convert a String to a Uri.

this code doesn't work

That is not a valid string representation of a Uri. A Uri has a scheme, and "/external/images/media/470939" does not have a scheme.

Convert String to Uri in Kotlin

val uri = Uri.parse(Uri_string)

or

val fileName = "example.jpg"
val path = "${Environment.getExternalStorageDirectory()}/$fileName"
val file = File(path);
val uri = Uri.fromFile(file);

Converting string to URI

You can use the new URI(string) constructor (for an URI) and the new URL(string) constructor for a URL.

But that won't work with a FileReader - it requires the URI scheme to be file:

If you want to read a remote file, you need something like:

Reader reader = new InputStreamReader(new URL(urlString).openStream(), encoding);

The encoding can be taken from HttpURLConnection obtained by url.openConnection(), but you can also set it to something specific if you know it in advance. (Btw, In the above example I've omitted all I/O resource management)

Note (thanks to @StephenC): the url string must be a valid URL, which means it must start with http://

How do I Convert a String to a System.Uri?

webbrowser1.Url property expects an object of type System.Uri and you are supplying just a String, which can't be converted automatically. Try the following:

webbrowser1.Url = new System.Uri(my.settings.website);

Java - Convert String to valid URI object

You might try: org.apache.commons.httpclient.util.URIUtil.encodeQuery in Apache commons-httpclient project

Like this (see URIUtil):

URIUtil.encodeQuery("http://www.google.com?q=a b")

will become:

http://www.google.com?q=a%20b

You can of course do it yourself, but URI parsing can get pretty messy...

Convert a string which contains uri paths to a arraylisturi

Your code is pretty good just make your array list type string and then take string value of uri.

In the .text(String.valueof(Imagepath)) use Uri.toString instead of String valueof

Example :

Uri uri;
String myUriString;
myUriString = uri.toString();


Related Topics



Leave a reply



Submit