Intent to open PDF file in Android N -
i have been trying open pdf file using intent. works fine devices prior adroid n. following code have used
file file = new file(griditems.get(position).getpath()); intent intent = null; if (build.version.sdk_int < 24) { intent = new intent(intent.action_view); intent.setdataandtype(uri.fromfile(file), "application/pdf"); intent.setflags(intent.flag_activity_no_history); } else { intent = new intent(); intent.setaction(intent.action_view); uri pdfuri = fileprovider.geturiforfile(gallerypdfactivity.this, getapplicationcontext() .getpackagename () + ".provider", file); intent.putextra(intent.extra_stream, pdfuri); intent.setflags(intent.flag_activity_no_history); intent.settype("application/pdf"); } try { if (intent.resolveactivity(getpackagemanager()) != null) startactivity(intent); else apputils.toast("no application found open pdf", gallerypdfactivity.this); } catch (exception e) { apputils.toast(e.getmessage(), gallerypdfactivity.this); }
the file chooser opens , have selected google pdf viewer open app. returns error "cannot display pdf(no file received)" . able open same file in devices prior android n
add flag_grant_read_uri_permission
on intent
in fileprovider
case. otherwise, other app has no access content. see the documentation.
Comments
Post a Comment