Converting of Uri to String
126,437
Solution 1
Uri to String
Uri uri;
String stringUri;
stringUri = uri.toString();
String to Uri
Uri uri;
String stringUri;
uri = Uri.parse(stringUri);
Solution 2
Uri is serializable, so you can save strings and convert it back when loading
when saving
String str = myUri.toString();
and when loading
Uri myUri = Uri.parse(str);
Solution 3
using Android KTX library u can parse easily
val uri = myUriString.toUri()
Solution 4
STRING TO URI.
Uri uri=Uri.parse("YourString");
URI TO STRING
Uri uri;
String andro=uri.toString();
happy coding :)
Solution 5
If you want to pass a Uri to another activity, try the method intent.setData(Uri uri) https://developer.android.com/reference/android/content/Intent.html#setData(android.net.Uri)
In another activity, via intent.getData() to obtain the Uri.
Author by
NewDroidDev
Updated on July 11, 2022Comments
-
NewDroidDev almost 2 years
Is it possible to convert an
Uri
toString
and vice versa? Because I want to get the theUri
converted intoString
to pass into another activity viaintent.putextra()
and if it's not possible can anyone suggest me a way how to pass selectedUri
into another activity? -
Alberto Solano about 10 yearsPlease provide more details. Add some notes about your choices. I think they could be helpful.