@UnstableApi
public final class UriUtil


Utility methods for manipulating URIs.

Summary

Public methods

static String
@UnstableApi
getRelativePath(Uri baseUri, Uri targetUri)

Calculates the relative path from a base URI to a target URI.

static boolean

Returns true if the URI is starting with a scheme component, false otherwise.

static Uri
removeQueryParameter(Uri uri, String queryParameterName)

Removes query parameter from a URI, if present.

static String
resolve(@Nullable String baseUri, @Nullable String referenceUri)

Performs relative resolution of a referenceUri with respect to a baseUri.

static Uri
resolveToUri(@Nullable String baseUri, @Nullable String referenceUri)

Like resolve, but returns a Uri instead of a String.

Public methods

getRelativePath

@UnstableApi
public static String getRelativePath(Uri baseUri, Uri targetUri)

Calculates the relative path from a base URI to a target URI.

Returns
String

The relative path from the base URI to the target URI, or targetUri if the URIs have different schemes or authorities.

isAbsolute

public static boolean isAbsolute(@Nullable String uri)

Returns true if the URI is starting with a scheme component, false otherwise.

removeQueryParameter

public static Uri removeQueryParameter(Uri uri, String queryParameterName)

Removes query parameter from a URI, if present.

Parameters
Uri uri

The URI.

String queryParameterName

The name of the query parameter.

Returns
Uri

The URI without the query parameter.

resolve

public static String resolve(@Nullable String baseUri, @Nullable String referenceUri)

Performs relative resolution of a referenceUri with respect to a baseUri.

The resolution is performed as specified by RFC-3986.

Parameters
@Nullable String baseUri

The base URI.

@Nullable String referenceUri

The reference URI to resolve.

resolveToUri

public static Uri resolveToUri(@Nullable String baseUri, @Nullable String referenceUri)

Like resolve, but returns a Uri instead of a String.

Parameters
@Nullable String baseUri

The base URI.

@Nullable String referenceUri

The reference URI to resolve.