-
-
Save EngrTAHAR-Noureddine/f4c3fdee1b923eed98df8574b9e3dfd4 to your computer and use it in GitHub Desktop.
Open PDF file Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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