i have one pdf file in internal storage of my device using below code to view pdf this code is working in all version of android except nougat.
Class to generate Pdf is as follows :
File dir = new File(Environment.getExternalStorageDirectory(), filepath);
if(!dir.exists()) {
dir.mkdir();
}
filename = "O"+pref.getCurrentOdrerId()+".pdf";
System.out.println("filename: "+filename);
pdfFile = new File(dir.getAbsoluteFile()+"/"+filename);
Uri uri;
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= Constants.ANDROID_NOUGAT) {
//uri = Uri.parse(pdfFile.getAbsolutePath());
uri = FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID + ".provider",
new File(pdfFile.getAbsolutePath()));
}
else{
uri = Uri.fromFile(new File(pdfFile.getAbsolutePath()));
}
WebView webView = (WebView) v.findViewById(R.id.showInvoicePdf);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new MyBrowser());
webView.loadUrl(uri.toString());//String.valueOf(new File(pdfFile.getAbsolutePath()))
Any help is appreciated!