Methods Summary |
---|
public java.lang.String | getExtensionFromMimeType(java.lang.String mimeType)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.
return MimeUtils.guessExtensionFromMimeType(mimeType);
|
public static java.lang.String | getFileExtensionFromUrl(java.lang.String url)Returns the file extension or an empty string iff there is no
extension. This method is a convenience method for obtaining the
extension of a url and has undefined results for other Strings.
if (!TextUtils.isEmpty(url)) {
int fragment = url.lastIndexOf('#");
if (fragment > 0) {
url = url.substring(0, fragment);
}
int query = url.lastIndexOf('?");
if (query > 0) {
url = url.substring(0, query);
}
int filenamePos = url.lastIndexOf('/");
String filename =
0 <= filenamePos ? url.substring(filenamePos + 1) : url;
// if the filename contains special characters, we don't
// consider it valid for our matching purposes:
if (!filename.isEmpty() &&
Pattern.matches("[a-zA-Z_0-9\\.\\-\\(\\)\\%]+", filename)) {
int dotPos = filename.lastIndexOf('.");
if (0 <= dotPos) {
return filename.substring(dotPos + 1);
}
}
}
return "";
|
public java.lang.String | getMimeTypeFromExtension(java.lang.String extension)Return the MIME type for the given extension.
return MimeUtils.guessMimeTypeFromExtension(extension);
|
public static android.webkit.MimeTypeMap | getSingleton()Get the singleton instance of MimeTypeMap.
return sMimeTypeMap;
|
public boolean | hasExtension(java.lang.String extension)Return true if the given extension has a registered MIME type.
return MimeUtils.hasExtension(extension);
|
public boolean | hasMimeType(java.lang.String mimeType)Return true if the given MIME type has an entry in the map.
return MimeUtils.hasMimeType(mimeType);
|
private static java.lang.String | mimeTypeFromExtension(java.lang.String extension)
return MimeUtils.guessMimeTypeFromExtension(extension);
|
java.lang.String | remapGenericMimeType(java.lang.String mimeType, java.lang.String url, java.lang.String contentDisposition)If the given MIME type is null, or one of the "generic" types (text/plain
or application/octet-stream) map it to a type that Android can deal with.
If the given type is not generic, return it unchanged.
// If we have one of "generic" MIME types, try to deduce
// the right MIME type from the file extension (if any):
if ("text/plain".equals(mimeType) ||
"application/octet-stream".equals(mimeType)) {
// for attachment, use the filename in the Content-Disposition
// to guess the mimetype
String filename = null;
if (contentDisposition != null) {
filename = URLUtil.parseContentDisposition(contentDisposition);
}
if (filename != null) {
url = filename;
}
String extension = getFileExtensionFromUrl(url);
String newMimeType = getMimeTypeFromExtension(extension);
if (newMimeType != null) {
mimeType = newMimeType;
}
} else if ("text/vnd.wap.wml".equals(mimeType)) {
// As we don't support wml, render it as plain text
mimeType = "text/plain";
} else {
// It seems that xhtml+xml and vnd.wap.xhtml+xml mime
// subtypes are used interchangeably. So treat them the same.
if ("application/vnd.wap.xhtml+xml".equals(mimeType)) {
mimeType = "application/xhtml+xml";
}
}
return mimeType;
|