Suppose I have a full path of file like:(/sdcard/tlogo.png). I want to know its mime type.
I created a function for it
public static String getMimeType(File file, Context context)
{
Uri uri = Uri.fromFile(file);
ContentResolver cR = context.getContentResolver();
MimeTypeMap mime = MimeTypeMap.getSingleton();
String type = mime.getExtensionFromMimeType(cR.getType(uri));
return type;
}
but when i call it, it returns null.
File file = new File(filePath);
String fileType=CommonFunctions.getMimeType(file, context);
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…