Is it possible to convert an Uri
to String
and vice versa?
Because I want to get the the Uri
converted into String
to pass into another activity via intent.putextra()
and if it's not possible can anyone suggest me a way how to pass selected Uri
into another activity?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Uri to String
Uri uri;
String stringUri;
stringUri = uri.toString();
String to Uri
Uri uri;
String stringUri;
uri = Uri.parse(stringUri);
回答2:
Uri is not 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);
回答3:
STRING TO URI.
Uri uri=Uri.parse("YourString");
URI TO STRING
Uri uri;
String andro=uri.toString();
happy coding :)
回答4:
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.
回答5:
using Android KTX library u can parse easily
val uri = myUriString.toUri()
回答6:
String to Uri
Uri myUri = Uri.parse("https://www.google.com");
Uri to String
Uri uri;
String stringUri = uri.toString();
回答7:
You can use .toString
method to convert Uri to String in java
Uri uri = Uri.parse("Http://www.google.com");
String url = uri.toString();
This method convert Uri to String easily
回答8:
Uri uri = new Uri("*");
string stringUri = uri.OriginalString;