我已经搜索过,但没有找到任何在应用程序中显示 pdf 文件的解决方案
关键是我必须显示来自 Assets 或原始文件夹的 pdf 而不是来自网络
我已经在 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();
}
关于android - 在应用程序中打开 Assets 文件 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5743807/