Partager via


URLUtil.GuessFileName(String, String, String) Method

Definition

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

[Android.Runtime.Register("guessFileName", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", "")]
public static string? GuessFileName (string? url, string? contentDisposition, string? mimeType);
[<Android.Runtime.Register("guessFileName", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", "")>]
static member GuessFileName : string * string * string -> string

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

suggested filename

Attributes

Remarks

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.

<ul> <li>For targetSDK versions &lt; VANILLA_ICE_CREAM it will be parsed based on RFC 2616. <li>For targetSDK versions &gt;= VANILLA_ICE_CREAM it will be parsed based on RFC 6266. </ul>

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:

<ul> <li>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. <li>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. </ul>

Java documentation for android.webkit.URLUtil.guessFileName(java.lang.String, java.lang.String, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to