Android Mime Type Get getMIMEType(String fName)

Here you can find the source of getMIMEType(String fName)

Description

get MIME Type

Declaration

public static String getMIMEType(String fName) 

Method Source Code

//package com.java2s;

public class Main {
    private static String[][] MIME_MapTable = {

    { ".3gp", "video/3gpp" },

    { ".asf", "video/x-ms-asf" },

    { ".avi", "video/x-msvideo" },

    { ".bmp", "image/bmp" },

    { ".gif", "image/gif" },

    { ".htm", "text/html" },

    { ".html", "text/html" },

    { ".jpeg", "image/jpeg" },

    { ".jpg", "image/jpeg" },

    { ".m4v", "video/x-m4v" },

    { ".mov", "video/quicktime" },

    { ".mp2", "audio/x-mpeg" },

    { ".mp3", "audio/x-mpeg" },

    { ".mp4", "video/mp4" },

    { ".mpe", "video/mpeg" },

    { ".mpeg", "video/mpeg" },

    { ".mpg", "video/mpeg" },

    { ".mpg4", "video/mp4" },

    { ".mpga", "audio/mpeg" },

    { ".ogg", "audio/ogg" },

    { ".png", "image/png" },

    { ".rmvb", "audio/x-pn-realaudio" },

    { ".wav", "audio/x-wav" },

    { ".wma", "audio/x-ms-wma" },

    { ".wmv", "audio/x-ms-wmv" },

    { "", "*/*" }

    };//from w w w  . j av a 2s.  c o  m

    public static String getMIMEType(String fName) {
        String type = "*/*";
        int dotIndex = fName.lastIndexOf(".");
        if (dotIndex < 0) {
            return type;
        }
        String end = fName.substring(dotIndex, fName.length())
                .toLowerCase();
        if (end == "")
            return type;
        for (int i = 0; i < MIME_MapTable.length; i++) {
            if (end.equals(MIME_MapTable[i][0]))
                type = MIME_MapTable[i][1];
        }
        return type;
    }
}

Related

  1. getMimeType(byte[] bytes)
  2. isRotationSupported(String mimeType)
  3. isSupportedByRegionDecoder(String mimeType)
  4. getMimeType(String url)
  5. guessMime(String path)