Stay organized with collections
Save and categorize content based on your preferences.
MimeTypeMap
open class MimeTypeMap
Two-way map that maps MIME-types to file extensions and vice versa.
See also java.net.URLConnection#guessContentTypeFromName
and java.net.URLConnection#guessContentTypeFromStream
. This class and URLConnection
share the same MIME-type database.
Summary
Public methods |
open String? |
Return the registered extension for the given MIME type.
|
open static String! |
Returns the file extension or an empty string if there is no extension.
|
open String? |
Return the MIME type for the given extension.
|
open static MimeTypeMap! |
Get the singleton instance of MimeTypeMap.
|
open Boolean |
Return true if the given extension has a registered MIME type.
|
open Boolean |
Return true if the given MIME type has an entry in the map.
|
Public methods
getExtensionFromMimeType
open fun getExtensionFromMimeType(mimeType: String!): String?
Return the registered extension for the given MIME type. Note that some MIME types map to multiple extensions. This call will return the most common extension for the given MIME type.
Parameters |
mimeType |
String!: A MIME type (i.e. text/plain) |
Return |
String? |
The extension for the given MIME type or null if there is none. |
getFileExtensionFromUrl
open static fun getFileExtensionFromUrl(url: String!): String!
Returns the file extension or an empty string if there is no extension. This method is a convenience method for obtaining the extension of a url and has undefined results for other Strings.
Return |
String! |
The file extension of the given url. |
getMimeTypeFromExtension
open fun getMimeTypeFromExtension(extension: String!): String?
Return the MIME type for the given extension.
Parameters |
extension |
String!: A file extension without the leading '.' |
Return |
String? |
The MIME type for the given extension or null if there is none. |
getSingleton
open static fun getSingleton(): MimeTypeMap!
Get the singleton instance of MimeTypeMap.
Return |
MimeTypeMap! |
The singleton instance of the MIME-type map. |
hasExtension
open fun hasExtension(extension: String!): Boolean
Return true
if the given extension has a registered MIME type.
Parameters |
extension |
String!: A file extension without the leading '.' |
Return |
Boolean |
true if there is an extension entry in the map. |
hasMimeType
open fun hasMimeType(mimeType: String!): Boolean
Return true
if the given MIME type has an entry in the map.
Parameters |
mimeType |
String!: A MIME type (i.e. text/plain) |
Return |
Boolean |
true if there is a mimeType entry in the map. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# MimeTypeMap\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nMimeTypeMap\n===========\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/webkit/MimeTypeMap \"View this page in Java\") \n\n```\nopen class MimeTypeMap\n```\n\n|---|---------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.webkit.MimeTypeMap](#) |\n\nTwo-way map that maps MIME-types to file extensions and vice versa.\n\nSee also [java.net.URLConnection#guessContentTypeFromName](../../java/net/URLConnection.html#guessContentTypeFromName(kotlin.String)) and [java.net.URLConnection#guessContentTypeFromStream](../../java/net/URLConnection.html#guessContentTypeFromStream(java.io.InputStream)). This class and `URLConnection` share the same MIME-type database.\n\nSummary\n-------\n\n| Public methods ||\n|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)? | [getExtensionFromMimeType](#getExtensionFromMimeType(kotlin.String))`(`mimeType:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Return the registered extension for the given MIME type. |\n| open static [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | [getFileExtensionFromUrl](#getFileExtensionFromUrl(kotlin.String))`(`url:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Returns the file extension or an empty string if there is no extension. |\n| open [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)? | [getMimeTypeFromExtension](#getMimeTypeFromExtension(kotlin.String))`(`extension:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Return the MIME type for the given extension. |\n| open static [MimeTypeMap](#)! | [getSingleton](#getSingleton())`()` Get the singleton instance of MimeTypeMap. |\n| open [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [hasExtension](#hasExtension(kotlin.String))`(`extension:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Return `true` if the given extension has a registered MIME type. |\n| open [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [hasMimeType](#hasMimeType(kotlin.String))`(`mimeType:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Return `true` if the given MIME type has an entry in the map. |\n\nPublic methods\n--------------\n\n### getExtensionFromMimeType\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getExtensionFromMimeType(mimeType: String!): String?\n```\n\nReturn the registered extension for the given MIME type. Note that some MIME types map to multiple extensions. This call will return the most common extension for the given MIME type.\n\n| Parameters ||\n|------------|------------------------------------------------------------------------------------------------------------------|\n| `mimeType` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: A MIME type (i.e. text/plain) |\n\n| Return ||\n|-----------------------------------------------------------------------------------|-------------------------------------------------------------------|\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)? | The extension for the given MIME type or `null` if there is none. |\n\n### getFileExtensionFromUrl\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen static fun getFileExtensionFromUrl(url: String!): String!\n```\n\nReturns the file extension or an empty string if there is no extension. This method is a convenience method for obtaining the extension of a url and has undefined results for other Strings.\n\n| Parameters ||\n|-------|------------------------------------------------------------------------------------|\n| `url` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: |\n\n| Return ||\n|-----------------------------------------------------------------------------------|--------------------------------------|\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | The file extension of the given url. |\n\n### getMimeTypeFromExtension\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getMimeTypeFromExtension(extension: String!): String?\n```\n\nReturn the MIME type for the given extension.\n\n| Parameters ||\n|-------------|-----------------------------------------------------------------------------------------------------------------------------|\n| `extension` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: A file extension without the leading '.' |\n\n| Return ||\n|-----------------------------------------------------------------------------------|-------------------------------------------------------------------|\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)? | The MIME type for the given extension or `null` if there is none. |\n\n### getSingleton\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen static fun getSingleton(): MimeTypeMap!\n```\n\nGet the singleton instance of MimeTypeMap.\n\n| Return ||\n|-------------------|----------------------------------------------|\n| [MimeTypeMap](#)! | The singleton instance of the MIME-type map. |\n\n### hasExtension\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun hasExtension(extension: String!): Boolean\n```\n\nReturn `true` if the given extension has a registered MIME type.\n\n| Parameters ||\n|-------------|-----------------------------------------------------------------------------------------------------------------------------|\n| `extension` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: A file extension without the leading '.' |\n\n| Return ||\n|------------------------------------------------------------------------------------|---------------------------------------------------|\n| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true` if there is an extension entry in the map. |\n\n### hasMimeType\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun hasMimeType(mimeType: String!): Boolean\n```\n\nReturn `true` if the given MIME type has an entry in the map.\n\n| Parameters ||\n|------------|------------------------------------------------------------------------------------------------------------------|\n| `mimeType` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: A MIME type (i.e. text/plain) |\n\n| Return ||\n|------------------------------------------------------------------------------------|-------------------------------------------------|\n| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true` if there is a mimeType entry in the map. |"]]