Created
April 1, 2021 16:50
-
-
Save gavelez/b9a4dd54184946ade92924ced71de751 to your computer and use it in GitHub Desktop.
Open PDF file Android
This file contains 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