我已经搜索过了,没有找到任何在应用程序中显示pdf文件的解决方案
关键是我必须从资产或原始文件夹显示pdf,而不是从web我已经在webview中尝试过代码
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setContentDescription("application/pdf");
webview.loadUrl("file:///android_asset/button11.pdf");
但是它不工作。
我需要帮助提前感谢
这是我用来从文件系统中读取pdf的代码,我希望它能有所帮助!
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();
}
你不能仅仅使用file:///android_asset/button11.pdf来访问file。不是文件系统路径。webview不会显示你的pdf,即使你得到文件的真实路径。
这是解决方案。https://stackoverflow.com/a/10981194/1635488
你可以使用Mozilla的PDF .js在Android应用程序的webview中显示PDF。这就是解决办法。
https://stackoverflow.com/a/21383356/2260073