EPUB的getMimeTypeFromExtension返回null

时间:2016-02-05 10:39:18

标签: android epub mediastore

我正在尝试获取epubfile的MIME类型,因为在Wikipedia上的监听是application/epub+zip。但是,该方法返回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文件?这是可能的,因为有应用程序可以做到这一点。 (月亮读者)

1 个答案:

答案 0 :(得分:0)

这很有效。

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();

        }