# URLUtil

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/webkit/URLUtil#pubctors)\|[Methods](https://developer.android.com/reference/android/webkit/URLUtil#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/webkit/URLUtil#inhmethods)  

# URLUtil

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/webkit/URLUtil "View this page in Kotlin")\|Java

`
public

final

class
URLUtil
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.webkit.URLUtil |

<br />

*** ** * ** ***

## Summary

|                                    ### Public constructors                                     ||
|---------------------------------------------------------------------------------------------|---|
| ` `[URLUtil](https://developer.android.com/reference/android/webkit/URLUtil#URLUtil())`() ` |

|                                                                                                                                                                                                                                                                                     ### Public methods                                                                                                                                                                                                                                                                                     ||
|------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[String](https://developer.android.com/reference/java/lang/String) | ` `[composeSearchUrl](https://developer.android.com/reference/android/webkit/URLUtil#composeSearchUrl(java.lang.String,%20java.lang.String,%20java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` inQuery, `[String](https://developer.android.com/reference/java/lang/String)` template, `[String](https://developer.android.com/reference/java/lang/String)` queryPlaceHolder) ` Inserts the`inQuery`in the`template`after URL-encoding it.                           |
| ` static byte[]`                                                             | ` `[decode](https://developer.android.com/reference/android/webkit/URLUtil#decode(byte[]))`(byte[] url) `                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` static `[String](https://developer.android.com/reference/java/lang/String) | ` `[guessFileName](https://developer.android.com/reference/android/webkit/URLUtil#guessFileName(java.lang.String,%20java.lang.String,%20java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url, `[String](https://developer.android.com/reference/java/lang/String)` contentDisposition, `[String](https://developer.android.com/reference/java/lang/String)` mimeType) ` Guesses canonical filename that a download would have, using the URL and contentDisposition. |
| ` static `[String](https://developer.android.com/reference/java/lang/String) | ` `[guessUrl](https://developer.android.com/reference/android/webkit/URLUtil#guessUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` inUrl) ` Cleans up (if possible) user-entered web addresses                                                                                                                                                                                                                                                                   |
| ` static boolean`                                                            | ` `[isAboutUrl](https://developer.android.com/reference/android/webkit/URLUtil#isAboutUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) `                                                                                                                                                                                                                                                                                                                    |
| ` static boolean`                                                            | ` `[isAssetUrl](https://developer.android.com/reference/android/webkit/URLUtil#isAssetUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) `                                                                                                                                                                                                                                                                                                                    |
| ` static boolean`                                                            | ` `[isContentUrl](https://developer.android.com/reference/android/webkit/URLUtil#isContentUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) `                                                                                                                                                                                                                                                                                                                |
| ` static boolean`                                                            | ` `[isCookielessProxyUrl](https://developer.android.com/reference/android/webkit/URLUtil#isCookielessProxyUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) ` *This method was deprecated in API level 15. Cookieless proxy is no longer supported.*                                                                                                                                                                                                         |
| ` static boolean`                                                            | ` `[isDataUrl](https://developer.android.com/reference/android/webkit/URLUtil#isDataUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) `                                                                                                                                                                                                                                                                                                                      |
| ` static boolean`                                                            | ` `[isFileUrl](https://developer.android.com/reference/android/webkit/URLUtil#isFileUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) `                                                                                                                                                                                                                                                                                                                      |
| ` static boolean`                                                            | ` `[isHttpUrl](https://developer.android.com/reference/android/webkit/URLUtil#isHttpUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) `                                                                                                                                                                                                                                                                                                                      |
| ` static boolean`                                                            | ` `[isHttpsUrl](https://developer.android.com/reference/android/webkit/URLUtil#isHttpsUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) `                                                                                                                                                                                                                                                                                                                    |
| ` static boolean`                                                            | ` `[isJavaScriptUrl](https://developer.android.com/reference/android/webkit/URLUtil#isJavaScriptUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) `                                                                                                                                                                                                                                                                                                          |
| ` static boolean`                                                            | ` `[isNetworkUrl](https://developer.android.com/reference/android/webkit/URLUtil#isNetworkUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) `                                                                                                                                                                                                                                                                                                                |
| ` static boolean`                                                            | ` `[isValidUrl](https://developer.android.com/reference/android/webkit/URLUtil#isValidUrl(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) `                                                                                                                                                                                                                                                                                                                    |
| ` static `[String](https://developer.android.com/reference/java/lang/String) | ` `[stripAnchor](https://developer.android.com/reference/android/webkit/URLUtil#stripAnchor(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` url) ` Strips the url of the anchor.                                                                                                                                                                                                                                                                                    |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### URLUtil

```
public URLUtil ()
```

<br />

<br />

## Public methods

### composeSearchUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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`.

<br />

|             Parameters              ||
|--------------------|-----------------|
| `inQuery`          | `String` <br /> |
| `template`         | `String` <br /> |
| `queryPlaceHolder` | `String` <br /> |

|                                  Returns                                   ||
|--------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String) | <br /> |

### decode

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static byte[] decode (byte[] url)
```

<br />

<br />

|      Parameters      ||
|-------|---------------|
| `url` | `byte` <br /> |

|     Returns      ||
|----------|--------|
| `byte[]` | <br /> |

|                                                  Throws                                                   ||
|--------------------------------------------------------------------------------------------------------|---|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) |   |

### guessFileName

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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.

<br />

<br />

|                                   Parameters                                    ||
|----------------------|-----------------------------------------------------------|
| `url`                | `String`: Url to the content <br />                       |
| `contentDisposition` | `String`: Content-Disposition HTTP header or`null` <br /> |
| `mimeType`           | `String`: Mime-type of the content or`null` <br />        |

|                                            Returns                                            ||
|--------------------------------------------------------------------|---------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | suggested filename <br /> |

### guessUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static String guessUrl (String inUrl)
```

Cleans up (if possible) user-entered web addresses

<br />

|        Parameters        ||
|---------|-----------------|
| `inUrl` | `String` <br /> |

|                                  Returns                                   ||
|--------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String) | <br /> |

### isAboutUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isAboutUrl (String url)
```

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                       Returns                        ||
|-----------|-------------------------------------------|
| `boolean` | `true`if the url is an about: url. <br /> |

### isAssetUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isAssetUrl (String url)
```

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                       Returns                        ||
|-----------|-------------------------------------------|
| `boolean` | `true`if the url is an asset file. <br /> |

### isContentUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isContentUrl (String url)
```

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                        Returns                        ||
|-----------|--------------------------------------------|
| `boolean` | `true`if the url is a content: url. <br /> |

### isCookielessProxyUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 15](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isCookielessProxyUrl (String url)
```

<br />

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

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                                                 Returns                                                 ||
|-----------|----------------------------------------------------------------------------------------------|
| `boolean` | `true`if the url is a proxy url to allow cookieless network requests from a file url. <br /> |

### isDataUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isDataUrl (String url)
```

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                      Returns                       ||
|-----------|-----------------------------------------|
| `boolean` | `true`if the url is a data: url. <br /> |

### isFileUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isFileUrl (String url)
```

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                       Returns                       ||
|-----------|------------------------------------------|
| `boolean` | `true`if the url is a local file. <br /> |

### isHttpUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isHttpUrl (String url)
```

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                       Returns                       ||
|-----------|------------------------------------------|
| `boolean` | `true`if the url is an http: url. <br /> |

### isHttpsUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isHttpsUrl (String url)
```

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                       Returns                        ||
|-----------|-------------------------------------------|
| `boolean` | `true`if the url is an https: url. <br /> |

### isJavaScriptUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isJavaScriptUrl (String url)
```

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                         Returns                          ||
|-----------|-----------------------------------------------|
| `boolean` | `true`if the url is a javascript: url. <br /> |

### isNetworkUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isNetworkUrl (String url)
```

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                       Returns                        ||
|-----------|-------------------------------------------|
| `boolean` | `true`if the url is a network url. <br /> |

### isValidUrl

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isValidUrl (String url)
```

<br />

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                   Returns                    ||
|-----------|-----------------------------------|
| `boolean` | `true`if the url is valid. <br /> |

### stripAnchor

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static String stripAnchor (String url)
```

Strips the url of the anchor.

<br />

|       Parameters       ||
|-------|-----------------|
| `url` | `String` <br /> |

|                                  Returns                                   ||
|--------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String) | <br /> |