Get MimeType from MimeTypeMap - Android android.webkit

Android examples for android.webkit:MimeTypeMap

Description

Get MimeType from MimeTypeMap

Demo Code

/*/*from w  ww .  j  a v  a  2 s .  c  om*/
 CanvasDrawUtils.java
 Copyright (c) 2015 NTT DOCOMO,INC.
 Released under the MIT license
 http://opensource.org/licenses/mit-license.php
 */
//package com.java2s;

import android.webkit.MimeTypeMap;

public class Main {
    /**
     * Get MimeType.
     *
     * @param url file's url
     * @return file's MimeType
     */
    public static String getMimeType(final String url) {
        String type = null;
        String extension = MimeTypeMap.getFileExtensionFromUrl(url);
        if (extension != null) {
            type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
                    extension);
        }
        return type;
    }
}

Related Tutorials