Open asset file pdf in application
I have searched already and not found any solution for show pdf file in application
The point is i have to show pdf from asset or raw folder not from web
I have already tried in webview with code
WebView webview = (WebView) findViewById(R.id.webview);
web开发者_Go百科view.getSettings().setJavaScriptEnabled(true);
webview.setContentDescription("application/pdf");
webview.loadUrl("file:///android_asset/button11.pdf");
but its not woking.
i need help on that thanks in advance
This is the code I use to read a pdf from the filesystem, I hope it helps!
File file = new File("/path/to/file");
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
context.startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(context, "No application available to view PDF", Toast.LENGTH_LONG).show();
}
You can't just use file:///android_asset/button11.pdf to access file. It isn't file system path. And webview will not show your pdf even if your get file real path.
Here is the solution. https://stackoverflow.com/a/10981194/1635488
you can use pdf.js from Mozilla to display a PDF in a webview inside an Android application. Here is the solution.
https://stackoverflow.com/a/21383356/2260073
精彩评论