2016-02-05 2 views
1

J'essaie d'obtenir le type MIME pour un epubfile, qui, comme l'écoute sur Wikipedia est application/epub+zip. Cependant, la méthode renvoie null.getMimeTypeFromExtension pour EPUB renvoie 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); 

Existe-t-il une autre méthode pour importer des fichiers epub? C'est possible, parce qu'il y a des applications qui font cela. (Moon Reader)

+0

[epub a été ajouté Jeu 11 décembre 2014 13:07:19] (https://android.googlesource.com/platform/libcore/+log/master/luni/src/main/java/libcore/ net/MimeUtils.java) ... donc chaque version android avant cela reviendrait évidemment null ... – Selvin

+0

Pouvez-vous confirmer la version android? –

+0

Et évidemment, comment est-ce que je fais fonctionner ceci pour des appareils plus anciens? –

Répondre

0

Cela fonctionne.

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

     }