What is the best way to determine file type in android? I want to check if the given file is image or music file or video or smth else. Could you please give me a small code snippet?
A:
Common way is by their extension only, or you can parse the header, but it should be too much slower and more complex for your apps.
Cytown
2010-01-11 07:57:17
+1
A:
- include some mime.types files in your assets folder (for example from /etc/mime.types)
- include activation.jar (from JAF) in your build path
- use something like
try {
MimetypesFileTypeMap mftm =
new MimetypesFileTypeMap(getAssets().open("mime.types"));
FileTypeMap.setDefaultFileTypeMap(mftm);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- then use
FileDataSource.getContentType()
to obtain file types
dtmilano
2010-01-11 16:18:15
ok. but I used android.webkit.MimeTypeMap
fixxer
2010-01-13 14:37:22