List of usage examples for android.webkit MimeTypeMap getMimeTypeFromExtension
@Nullable
public String getMimeTypeFromExtension(String extension)
From source file:Main.java
public static String getMimeTypeFromFileExtension(String extension, String defaultType) { MimeTypeMap mtm = MimeTypeMap.getSingleton(); String mimetype = defaultType; if (extension != null) { String type = mtm.getMimeTypeFromExtension(extension); if (type != null) { mimetype = type;//from w w w . j av a2 s . c o m } else { String lowerExtension = extension.toLowerCase(); if (EXTRA_MIMETYPES.containsKey(lowerExtension)) { mimetype = EXTRA_MIMETYPES.get(lowerExtension); } } } return mimetype; }
From source file:com.vk.sdk.api.httpClient.VKMultipartEntity.java
protected static String getMimeType(String url) { String type = null;//from w w w. jav a 2s . c o m String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (extension != null) { MimeTypeMap mime = MimeTypeMap.getSingleton(); type = mime.getMimeTypeFromExtension(extension); } return type; }
From source file:Main.java
public static String getMIMETypeFromUrl(final File file, final String defaultValue) { MimeTypeMap mime = MimeTypeMap.getSingleton(); int index = file.getName().lastIndexOf('.') + 1; String ext = file.getName().substring(index).toLowerCase(); final String mimeType = mime.getMimeTypeFromExtension(ext); if (mimeType != null) { return mimeType; }/*from ww w. j a va 2 s . c o m*/ return defaultValue; }
From source file:Main.java
public static String getMimeType(String url, String defaultType) { MimeTypeMap mtm = MimeTypeMap.getSingleton(); String extension = MimeTypeMap.getFileExtensionFromUrl(url); String mimetype = defaultType; if (extension != null) { String type = mtm.getMimeTypeFromExtension(extension); if (type != null) { mimetype = type;// w ww . j av a 2 s.c o m } } return mimetype; }
From source file:Main.java
public static String getMimetype(String fileName, String def) { String mimeType = "application/octet-stream"; try {//from w w w . ja va 2 s . co m MimeTypeMap mimeMap = MimeTypeMap.getSingleton(); int idx = fileName.lastIndexOf('.'); if (idx != -1) { String ext = fileName.substring(idx + 1); mimeType = mimeMap.getMimeTypeFromExtension(ext.toLowerCase()); } if (mimeType == null) { mimeType = def == null ? "application/octet-stream" : def; } } catch (Exception e) { } return mimeType; }
From source file:no.digipost.android.utilities.FileUtilities.java
public static String getMimeType(File file) { MimeTypeMap mime = MimeTypeMap.getSingleton(); String ext = FilenameUtils.getExtension(file.getName()); return mime.getMimeTypeFromExtension(ext); }
From source file:de.petermoesenthin.alarming.util.FileUtil.java
/** * Returns a mime type for a file in given path. * * @param path Path to the file.//from w w w. ja v a 2s . c o m * @return Null if no MIME type is found. */ public static String getMimeType(Context context, String path) { Log.d(DEBUG_TAG, "Checking mime type for " + path); String mimeType = null; String extension = FilenameUtils.getExtension(path); if (extension != null) { MimeTypeMap mime = MimeTypeMap.getSingleton(); mimeType = mime.getMimeTypeFromExtension(extension); Log.d(DEBUG_TAG, "MimeTypeMap found " + mimeType + " for extension " + extension); } if (mimeType == null) { ContentResolver contentResolver = context.getContentResolver(); mimeType = contentResolver.getType(Uri.parse(path)); Log.d(DEBUG_TAG, "ContentResolver found " + mimeType + "."); } return mimeType; }
From source file:Main.java
/** * Return the MIME type from the URI//from w ww. jav a 2s . co m * @param context Context * @param uri URI * @return Return the MIME type */ public static String getMimetypeFromUri(Context context, Uri uri) { String contentType = context.getContentResolver().getType(uri); if (TextUtils.isEmpty(contentType)) { final MimeTypeMap type_map = MimeTypeMap.getSingleton(); // Get the extension from the path String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString()); extension = extension.toLowerCase(); if (extension.contains(".")) { extension = extension.substring(extension.lastIndexOf(".")); } contentType = type_map.getMimeTypeFromExtension(extension); } return contentType; }
From source file:com.lovejoy777sarootool.rootool.preview.MimeTypes.java
public static String getMimeType(File file) { if (file.isDirectory()) { return null; }//from ww w . java2s.c om String type = null; final String extension = FilenameUtils.getExtension(file.getName()); if (extension != null && !extension.isEmpty()) { final String extensionLowerCase = extension.toLowerCase(Locale.getDefault()); final MimeTypeMap mime = MimeTypeMap.getSingleton(); type = mime.getMimeTypeFromExtension(extensionLowerCase); if (type == null) { type = MIME_TYPES.get(extensionLowerCase); } } return type; }
From source file:com.dnielfe.manager.preview.MimeTypes.java
@Nullable public static String getMimeType(File file) { if (file.isDirectory()) { return null; }//from w w w .j av a 2 s . c o m String type = null; final String extension = FilenameUtils.getExtension(file.getName()); if (extension != null && !extension.isEmpty()) { final String extensionLowerCase = extension.toLowerCase(Locale.getDefault()); final MimeTypeMap mime = MimeTypeMap.getSingleton(); type = mime.getMimeTypeFromExtension(extensionLowerCase); if (type == null) { type = MIME_TYPES.get(extensionLowerCase); } } return type; }