25
วิธีการระบุประเภทไฟล์ MIME ใน Android?
สมมติว่าฉันมีเส้นทางแบบเต็มเช่น: (/ sdcard / tlogo.png) ฉันต้องการทราบประเภท mime ของมัน ฉันสร้างฟังก์ชั่นสำหรับมัน 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; } แต่เมื่อฉันเรียกมันจะคืนค่าเป็นศูนย์ File file = new File(filePath); String fileType=CommonFunctions.getMimeType(file, context);