# URLUtilCompat

# URLUtilCompat

Artifact:[androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit)  
[View Source](https://cs.android.com/search?q=file:androidx/webkit/URLUtilCompat.java+class:androidx.webkit.URLUtilCompat)  
Added in[1.11.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.11.0)

*** ** * ** ***

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

<br />

```
class URLUtilCompat
```

<br />

*** ** * ** ***

Compatibility versions of methods in[android.webkit.URLUtil](https://developer.android.com/reference/android/webkit/URLUtil.html).  

|                                    See also                                    |
|--------------------------------------------------------------------------------|---|
| [URLUtil](https://developer.android.com/reference/android/webkit/URLUtil.html) |   |

## Summary

|                                        ### Public functions                                        |
|----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | [getFilenameFromContentDisposition](https://developer.android.com/reference/kotlin/androidx/webkit/URLUtilCompat#getFilenameFromContentDisposition(java.lang.String))`(contentDisposition: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Extract filename from a`Content-Disposition`header value.                                                                                                                                                                                                                         |
| `java-static `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)    | [guessFileName](https://developer.android.com/reference/kotlin/androidx/webkit/URLUtilCompat#guessFileName(java.lang.String,java.lang.String,java.lang.String))`(url: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, contentDisposition: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?, mimeType: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?)` Guesses canonical filename that a download would have, using the URL and contentDisposition. |

## Public functions

### getFilenameFromContentDisposition

Added in[1.11.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.11.0)  

```
java-static fun getFilenameFromContentDisposition(contentDisposition: String): String?
```

Extract filename from a`Content-Disposition`header value.

This method implements the parsing defined in[RFC 6266](https://datatracker.ietf.org/doc/html/rfc6266), supporting both the`filename`and`filename*`disposition parameters. If the passed header value has the`"inline"`disposition type, this method will return`null`to indicate that a download was not intended.

If both`filename*`and`filename`is present, the former will be returned, as per the RFC. Invalid encoded values will be ignored.  

|                                               Parameters                                                |
|---------------------------------------------------------------------------------------------------------|--------------------------------------|
| `contentDisposition: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Value of`Content-Disposition`header. |

|                                       Returns                                        |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | The filename suggested by the header or`null`if no filename could be parsed from the header value. |

### guessFileName

Added in[1.11.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.11.0)  

```
java-static fun guessFileName(url: String, contentDisposition: String?, mimeType: String?): String
```

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

This method differs from[guessFileName](https://developer.android.com/reference/android/webkit/URLUtil.html#guessFileName(java.lang.String, java.lang.String, java.lang.String))in the following ways:

- This method uses an updated parsing of`contentDisposition`, making this available on older Android versions. See[getFilenameFromContentDisposition](https://developer.android.com/reference/kotlin/androidx/webkit/URLUtilCompat#getFilenameFromContentDisposition(java.lang.String)).
- If the`contentDisposition`parameter is valid and contains a filename, that filename will be returned. The`url`and`mimeType`parameters will not be used in this case.
- Otherwise the filename will be deduced from the path of the`url`and the`mimeType`. If a`mimeType`is provided and the canonical extension for that filetype does not match the filename derived from the`url`, then the canonical extension will be appended.
- If the`mimeType`is`null`,`"application/octet-stream"`, or not known by the system, no extension will be appended to the filename.

|                                                 Parameters                                                 |
|------------------------------------------------------------------------------------------------------------|------------------------------------------|
| `url: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                   | Url to the content. Must not be`null`    |
| `contentDisposition: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | Content-Disposition HTTP header or`null` |
| `mimeType: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`           | Mime-type of the content or`null`        |

|                                      Returns                                      |
|-----------------------------------------------------------------------------------|--------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | suggested filename |

|                                                                               See also                                                                                |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [guessFileName](https://developer.android.com/reference/android/webkit/URLUtil.html#guessFileName(java.lang.String, java.lang.String, java.lang.String))              |   |
| [getFilenameFromContentDisposition](https://developer.android.com/reference/kotlin/androidx/webkit/URLUtilCompat#getFilenameFromContentDisposition(java.lang.String)) |   |