Figuring out Mimetypes for Android

Posted on August 1, 2011

0


Mime artist -- not quite what you think about when I say mimetype but yeah... they're funny in the cartoons.

Mime artist -- not quite what you think about when I say "mimetype" but yeah... they're funny in the cartoons.

Where Can I View The MimeTypes Supported By Android?

The mimetypes for Android are stored somewhere on a database, but sadly I have not yet found a published version of this list that developers can use for reference. In most cases, the developer would at least know the extension of the file. This could actually be sufficient information to get the answer.

Android has a MimeTypeMap which can be used to get a few helpful bits of information. Methods such as getMimeTypeFromExtension, hasMimeType and getFileExtensionFromUrl are pretty self-explanatory — no need to waste more words on them.

Pulling The MimeType Information From Android’s Database

This bit of code demonstrates how one could squeeze the necessary information from the map.

import android.app.Activity;
import android.os.Bundle;
//...
import android.util.Log;
import android.webkit.MimeTypeMap;

public class SqueezeMap extends Activity{
   public static final String TAG = "MapSqueezer";

   public void onCreate(Bundle icicle){
      //... here comes the usual stuff -- invoke super.onCreate and inflate layout
      MimeTypeMap map = MimeTypeMap.getSingleton();
      Log.v(TAG, "your answer: " + map.getMimeTypeFromExtension(3gp));
   }
}

You just need to import MimeTypeMap and insert the last two (and only significant) lines of code from the onCreate method in the snippet. The methods that can be invoked are documented in the Android Developers Reference (see Reference).
Log or Toast the information to your liking. BTW: I’ve you’re not using Log then there is probably little use of importing android.util.Log but you most likely use it for some real logging so… whatever. I haven’t had and most likely will not have the time to look for a better way to get this information, there might even be a page that has all the answers on the Android Developers site which I happened to have overlooked… I’m just sayin’… could’ve missed it😦 so keep on looking and let me know if your find the ultimate source of information regarding this topic.

Happy coding😉

Posted in: coding