Java: how to get a File’s Mime Type


Use android.webkit.MimeTypeMap

Code snippet java:

import android.webkit.MimeTypeMap;
...
    public static String getMimeType(String url) {
        String type = null;
        String extension = MimeTypeMap.getFileExtensionFromUrl(url.replace(" ","%20"));
        if (extension != null) {
            type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        }
        return type;
    }

Leave a Reply