Search code examples
androidpdfepubandroid-studio-3.0

Android Studio - Open epub + pdf files from default directory application (Programmatically)


How to open default file manager app that let you choose a file but only with extension .epub or .pdf programatically via Intent?


Solution

  • The code shown is the declaration of the intent that you have to start for opening the default file manager app that let you choose a file but only with extension .epub or .pdf, I hope it will be useful.

    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("application/epub+zip");
    String[] mimetypes = {"application/epub+zip", "application/pdf"};
    intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
    startActivityForResult(intent,PICKFILE_RESULT_CODE);
    

    It is a mix of solutions I found that work so maybe it is redundant. Let me know what you think!