As far as I'm aware there's only three ways to get the MIME type from reading the existing questions.
1) Determining it from the file extension using MimeTypeMap.getFileExtensionFromUrl
2) "Guess" using the inputStream
with URLConnection.guessContentTypeFromStream
3) Using the ContentResolver
to get the MIME type using content Uri (content:\) context.getContentResolver().getType
However, I only have the file object, with the obtainable Uri
being the file path Uri
(file:). The file does not have an extension. Is there still a way to get the MIME type of the file? Or a way to determine the content Uri from the file path Uri?
Best Answer
Have you tried this? It works for me (only for image files).
Of course you can also use other methods, such as
BitmapFactory.decodeFile
orBitmapFactory.decodeResource
like this:It will return null if failed to determine the MIME type.