Skip to content

Instantly share code, notes, and snippets.

@EngrTAHAR-Noureddine
Forked from gavelez/open_pdf.java
Created December 9, 2023 15:04
Show Gist options
  • Save EngrTAHAR-Noureddine/f4c3fdee1b923eed98df8574b9e3dfd4 to your computer and use it in GitHub Desktop.
Save EngrTAHAR-Noureddine/f4c3fdee1b923eed98df8574b9e3dfd4 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