用于EPUB的getMimeTypeFromExtension返回null
问题描述:
我正在尝试获取epubfile的MIME类型,其中,作为维基百科上的听是application/epub+zip
。但是,该方法返回null。用于EPUB的getMimeTypeFromExtension返回null
Uri uri = MediaStore.Files.getContentUri("external");
String[] projection = null;
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
String[] selectionArgs = null; // there is no ? in selection so null here
String sortOrder = null; // unordered
String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE + "=?";
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("epub"); //this line here returns null
// String mimeType = "application/epub+zip" this returns null too.
String[] selectionArgsPdf = new String[]{ mimeType };
Cursor cur = cr.query(uri, projection, selectionMimeType, selectionArgsPdf, sortOrder);
是否有其他方法导入epub文件?这是可能的,因为有些应用可以做到这一点。 (Moon Reader)
答
This works。
Uri uri = MediaStore.Files.getContentUri("external");
// every column, although that is huge waste, you probably need
// BaseColumns.DATA (the path) only.
String[] projection = null;
// exclude media files, they would be here also.
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
String[] selectionArgs = null; // there is no ? in selection so null here
Cursor cur = cr.query(uri, projection, selection,selectionArgs,null);
int NumberOfPDFS =cur.getCount();
cl(Integer.toString(NumberOfPDFS));
cur.moveToFirst();
while (cur.isAfterLast() == false) {
if(cur.getString(1).lastIndexOf(".epub")!=-1){
//do whatever.
}
cur.moveToNext();
}
cur.close();
}
[加入的epub星期四12月11日13时07分19秒2014](https://android.googlesource.com/platform/libcore/+log/master/luni/src/main/java/libcore/ net/MimeUtils.java)...所以在此之前的每个Android版本显然都会返回null ... – Selvin
您可以确认Android版本吗? –
很明显,我如何为旧设备做这项工作? –