Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell what's the MIME type according to the file?

Is there any elegant way (not just if ("fileExt".compareTo(".mp3")) {MIME_TYPE = "audio/*"}) to learn programatically the MIME type that should be put into an intent, with which I have to open the file?

Thanks!

like image 669
karla Avatar asked Dec 11 '10 08:12

karla


People also ask

How do I find the MIME type of a file?

For detecting MIME-types, use the aptly named "mimetype" command. It has a number of options for formatting the output, it even has an option for backward compatibility to "file". But most of all, it accepts input not only as file, but also via stdin/pipe, so you can avoid temporary files when processing streams.

What is the MIME type for text file?

Two primary MIME types are important for the role of default types: text/plain is the default value for textual files. A textual file should be human-readable and must not contain binary data. application/octet-stream is the default value for all other cases.

How do I specify a MIME type?

In the Connections pane, go to the site, application, or directory for which you want to add a MIME type. In the Home pane, double-click MIME Types. In the MIME Types pane, click Add... in the Actions pane. In the Add MIME Type dialog box, add the file name extension and MIME type, and then click OK.

What is the MIME type for CSV file?

On a Windows machine with Microsoft Excel installed, CSV files may have a MIME type of application/vnd.


1 Answers

well it does the same as your if statement but is slightly more elegant

Use the MimeTypeMap class

http://developer.android.com/reference/android/webkit/MimeTypeMap.html

like image 120
kgutteridge Avatar answered Sep 18 '22 20:09

kgutteridge