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
Android: How to Hide Actionbar on Certain Activities
How to Get Selected Xls File Path from Uri for Sdk 17 or Below for Android
Encrypt with Node.Js Crypto Module and Decrypt with Java (In Android App)
Android - Bitmap Cache Takes a Lot of Memory
Read Data from SQLite Where Column Name Contains Spaces
Svg/Vector Graphical Objects Boolean Operations (Union, Intersection, Subtraction)
Jsoup Get Dynamically Generated HTML
How to Set -Source 1.7 in Android Studio and Gradle
How to Calculate the Pixel Width of a String in Javafx
Why Do Variable Names Often Start with the Letter 'M'
Android Studio - Failed to Find Target Android-18
Gradle Sync Failed: Unable to Find Method