如何在android浏览器中打开pdf文件?

时间:2013-10-01 07:39:52

标签: android pdf browser

我的html页面上有本地pdf文件的链接。我想在没有活动的互联网连接的情况下在浏览器(chrome,opera,dolphin)中打开这个pdf文件。您可以知道插件,可以在浏览器或方法或其他内容中打开pdf文件(无需下载)吗?

3 个答案:

答案 0 :(得分:2)

我曾经使用的解决方案是使用Google文档打开它们。

_webView.loadUrl("https://docs.google.com/gview?embedded=true&url="+ url);

答案 1 :(得分:2)

不幸的是,Android设备上的本机浏览器不支持此类文件。让我们看看在4.0+中我们是否能够做到这一点。

答案 2 :(得分:1)

使用以下代码:

CustomWebView webView = (CustomWebView) rootView.findViewById(R.id.webView);
webView.loadUrl("https://docs.google.com/gview?embedded=true&url=" + yourUrl);

制作CustomWebView类,如下所示:

public class CustomWebView extends WebView {
    private Context context;

    private ProgressDialog progressDialog;

    public CustomWebView(Context context) {
        super(context);
        this.context = context;
        init();
    }

    public CustomWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
        init();
    }

    private void init() {
        setWebSetting();
    }

    private void setWebSetting() {
        WebSettings webSettings = getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setPluginsEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        webSettings.setLightTouchEnabled(false);
        setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY);
        setWebViewClient(new CustomWebViewClient());
    }

    class CustomWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            progressDialog = ProgressDialog.show(context, null,
                    context.getString(R.string.msg_please_wait));
            progressDialog.setCancelable(false);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressDialog.dismiss();
        }
    }
}
相关问题