Skip to content

Instantly share code, notes, and snippets.

@gavelez
Created April 1, 2021 16:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gavelez/b9a4dd54184946ade92924ced71de751 to your computer and use it in GitHub Desktop.
Save gavelez/b9a4dd54184946ade92924ced71de751 to your computer and use it in GitHub Desktop.
Open PDF file Android
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
File file=new File(mFilePath);
Uri uri = FileProvider.getUriForFile(this, getPackageName() + ".provider", file);
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
} else {
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(mFilePath), "application/pdf");
intent = Intent.createChooser(intent, "Open File");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment