Converting of Uri to String

前端 未结 7 781
你的背包
你的背包 2020-12-12 20:01

Is it possible to convert an Uri to String and vice versa? Because I want to get the the Uri converted into String to pas

相关标签:
7条回答
  • 2020-12-12 20:24

    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);
    
    0 讨论(0)
  • 2020-12-12 20:30

    Uri to String

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

    String to Uri

    Uri uri;
    String stringUri;
    uri = Uri.parse(stringUri);
    
    0 讨论(0)
  • 2020-12-12 20:33

    String to Uri

    Uri myUri = Uri.parse("https://www.google.com");
    

    Uri to String

    Uri uri;
    String stringUri = uri.toString();
    
    0 讨论(0)
  • 2020-12-12 20:36

    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.

    0 讨论(0)
  • 2020-12-12 20:40

    using Android KTX library u can parse easily

    val uri = myUriString.toUri()
    
    0 讨论(0)
  • 2020-12-12 20:41

    STRING TO URI.

    Uri uri=Uri.parse("YourString");
    

    URI TO STRING

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

    happy coding :)

    0 讨论(0)
提交回复
热议问题