URLUtilCompat
class URLUtilCompat
Compatibility versions of methods in android.webkit.URLUtil.
| See also | |
|---|---|
URLUtil |
Summary
Public functions |
|
|---|---|
java-static String? |
getFilenameFromContentDisposition(contentDisposition: String)Extract filename from a |
java-static String |
guessFileName(url: String, contentDisposition: String?, mimeType: String?)Guesses canonical filename that a download would have, using the URL and contentDisposition. |
Public functions
getFilenameFromContentDisposition
java-static fun getFilenameFromContentDisposition(contentDisposition: String): String?
Extract filename from a Content-Disposition header value.
This method implements the parsing defined in RFC 6266, 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 |
Value of |
| Returns | |
|---|---|
String? |
The filename suggested by the header or |
guessFileName
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 in the following ways:
- This method uses an updated parsing of
contentDisposition, making this available on older Android versions. SeegetFilenameFromContentDisposition. - If the
contentDispositionparameter is valid and contains a filename, that filename will be returned. TheurlandmimeTypeparameters will not be used in this case. - Otherwise the filename will be deduced from the path of the
urland themimeType. If amimeTypeis provided and the canonical extension for that filetype does not match the filename derived from theurl, then the canonical extension will be appended. - If the
mimeTypeisnull,"application/octet-stream", or not known by the system, no extension will be appended to the filename.
| Parameters | |
|---|---|
url: String |
Url to the content. Must not be |
contentDisposition: String? |
Content-Disposition HTTP header or |
mimeType: String? |
Mime-type of the content or |
| Returns | |
|---|---|
String |
suggested filename |