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!
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.
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.
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.
On a Windows machine with Microsoft Excel installed, CSV files may have a MIME type of application/vnd.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With