如何在Android开放中的WebView本地PDF文件? [英] How to open local pdf file in webview in android?

查看:1769
本文介绍了如何在Android开放中的WebView本地PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在web视图中打开本地(SD卡)的PDF文件。

i want to open local(sdcard) pdf file in webview.

我已经尝试这一点,也有很多尝试:

i already try this and also many try:

webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setPluginsEnabled(true);
        webview.getSettings().setAllowFileAccess(true);
        File file = new File(Environment.getExternalStorageDirectory()
                + "/test.pdf");

        final Uri uri = Uri.fromFile(file);

        webview.loadUrl(uri.toString());

但仍然没有打开它,所以让我知道我可以在web视图中打开PDF文件?

but still not open it so let me know how i can open pdf in webview?

问候, 吉里什

推荐答案

您不能。

try
{
 Intent intentUrl = new Intent(Intent.ACTION_VIEW);
 intentUrl.setDataAndType(uri, "application/pdf");
 intentUrl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 mActivity.startActivity(intentUrl);
}
catch (ActivityNotFoundException e)
{
 Toast.makeText(mActivity, "No PDF Viewer Installed", Toast.LENGTH_LONG).show();
}

这篇关于如何在Android开放中的WebView本地PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆