Added in API level 1

URLUtil


public final class URLUtil
extends Object

java.lang.Object
   ↳ android.webkit.URLUtil


Summary

Public constructors

URLUtil()

Public methods

static String composeSearchUrl(String inQuery, String template, String queryPlaceHolder)

Inserts the inQuery in the template after URL-encoding it.

static byte[] decode(byte[] url)
static String guessFileName(String url, String contentDisposition, String mimeType)

Guesses canonical filename that a download would have, using the URL and contentDisposition.

static String guessUrl(String inUrl)

Cleans up (if possible) user-entered web addresses

static boolean isAboutUrl(String url)
static boolean isAssetUrl(String url)
static boolean isContentUrl(String url)
static boolean isCookielessProxyUrl(String url)

This method was deprecated in API level 15. Cookieless proxy is no longer supported.

static boolean isDataUrl(String url)
static boolean isFileUrl(String url)
static boolean isHttpUrl(String url)
static boolean isHttpsUrl(String url)
static boolean isJavaScriptUrl(String url)
static boolean isNetworkUrl(String url)
static boolean isValidUrl(String url)
static String stripAnchor(String url)

Strips the url of the anchor.

Inherited methods

Public constructors

URLUtil

public URLUtil ()

Public methods

composeSearchUrl

Added in API level 1
public static String composeSearchUrl (String inQuery, 
                String template, 
                String queryPlaceHolder)

Inserts the inQuery in the template after URL-encoding it. The encoded query will replace the queryPlaceHolder.

Parameters
inQuery String

template String

queryPlaceHolder String

Returns
String

decode

Added in API level 1
public static byte[] decode (byte[] url)

Parameters
url byte

Returns
byte[]

Throws
IllegalArgumentException

guessFileName

Added in API level 1
public static String guessFileName (String url, 
                String contentDisposition, 
                String mimeType)

Guesses canonical filename that a download would have, using the URL and contentDisposition.

File extension, if not defined, is added based on the mimetype.

The contentDisposition argument will be treated differently depending on targetSdkVersion.

  • For targetSDK versions < VANILLA_ICE_CREAM it will be parsed based on RFC 2616.
  • For targetSDK versions >= VANILLA_ICE_CREAM it will be parsed based on RFC 6266.
In practice, this means that from VANILLA_ICE_CREAM, this method will be able to parse filename* directives in the contentDisposition string.

The function also changed in the following ways in VANILLA_ICE_CREAM:

  • If the suggested file type extension doesn't match the passed mimeType, the method will append the appropriate extension instead of replacing the current extension.
  • If the suggested file name contains a path separator ("/"), the method will replace this with the underscore character ("_") instead of splitting the result and only using the last part.

Parameters
url String: Url to the content

contentDisposition String: Content-Disposition HTTP header or null

mimeType String: Mime-type of the content or null

Returns
String suggested filename

guessUrl

Added in API level 1
public static String guessUrl (String inUrl)

Cleans up (if possible) user-entered web addresses

Parameters
inUrl String

Returns
String

isAboutUrl

Added in API level 1
public static boolean isAboutUrl (String url)

Parameters
url String

Returns
boolean true if the url is an about: url.

isAssetUrl

Added in API level 1
public static boolean isAssetUrl (String url)

Parameters
url String

Returns
boolean true if the url is an asset file.

isContentUrl

Added in API level 1
public static boolean isContentUrl (String url)

Parameters
url String

Returns
boolean true if the url is a content: url.

isCookielessProxyUrl

Added in API level 1
Deprecated in API level 15
public static boolean isCookielessProxyUrl (String url)

This method was deprecated in API level 15.
Cookieless proxy is no longer supported.

Parameters
url String

Returns
boolean true if the url is a proxy url to allow cookieless network requests from a file url.

isDataUrl

Added in API level 1
public static boolean isDataUrl (String url)

Parameters
url String

Returns
boolean true if the url is a data: url.

isFileUrl

Added in API level 1
public static boolean isFileUrl (String url)

Parameters
url String

Returns
boolean true if the url is a local file.

isHttpUrl

Added in API level 1
public static boolean isHttpUrl (String url)

Parameters
url String

Returns
boolean true if the url is an http: url.

isHttpsUrl

Added in API level 1
public static boolean isHttpsUrl (String url)

Parameters
url String

Returns
boolean true if the url is an https: url.

isJavaScriptUrl

Added in API level 1
public static boolean isJavaScriptUrl (String url)

Parameters
url String

Returns
boolean true if the url is a javascript: url.

isNetworkUrl

Added in API level 1
public static boolean isNetworkUrl (String url)

Parameters
url String

Returns
boolean true if the url is a network url.

isValidUrl

Added in API level 1
public static boolean isValidUrl (String url)

Parameters
url String

Returns
boolean true if the url is valid.

stripAnchor

Added in API level 1
public static String stripAnchor (String url)

Strips the url of the anchor.

Parameters
url String

Returns
String