Android examples for Network:MIME
Returns the MIME type for a given file name, based on its extension.
//package com.java2s; import android.util.Log; public class Main { /**/*from w w w. ja va 2 s . c o m*/ * Returns the MIME type for a given file name, based on its extension. * * @param filename * @return MIME type; "" if unknown; null if filename is null. */ public static String getMimeType(String filename) { String mimeType = null; if (filename == null) { return mimeType; } if (filename.endsWith(".3gp")) { mimeType = "video/3gpp"; } else if (filename.endsWith(".mid")) { mimeType = "audio/mid"; } else if (filename.endsWith(".mp3")) { mimeType = "audio/mpeg"; } else if (filename.endsWith(".xml")) { mimeType = "text/xml"; } else { Log.i("TAG", "Unknown media type of file '" + filename + "'"); mimeType = ""; } return mimeType; } }