Convert java.net.URI to android.net.Uri

前端 未结 3 385
不思量自难忘°
不思量自难忘° 2021-01-01 13:17

I am able to find how to convert android.net.Uri to Java.net.URI here but not vice-versa.

So after spending some time I figured it out. Here is the solution(If ther

3条回答
  •  鱼传尺愫
    2021-01-01 14:08

    For anyone coming across this, I had success with the following code:

    URI oldUri;
    Uri newUri  = new Uri.Builder().scheme(oldUri.getScheme())
                        .encodedAuthority(oldUri.getRawAuthority())
                        .encodedPath(oldUri.getRawPath())
                        .query(oldUri.getRawQuery())
                        .fragment(oldUri.getRawFragment())
                        .build();
    

    Basically, get each URI component and pass it to the builder (as there does not seem to be a way to pass in a whole URI string.

提交回复
热议问题