使用WebView在Android中显示PDF

时间:2013-09-05 06:35:14

标签: android android-webview

我正在尝试使用WebView在Android中显示PDF,我正在使用google docs来实现此目的。直到今天早上工作正常。但是突然间它发出了502错误。 有没有替代方法可以在WebView中显示PDF。

这是我用于在WebView

中呈现PDF的网址

https://docs.google.com/gview?embedded=true&url= + URL

看起来https://docs.google.com/gview?embedded=true&url=已关闭。

1 个答案:

答案 0 :(得分:1)

试试这种方式

@Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        if (url.endsWith(".pdf"))
        {
            // Load "url" in google docs

           String googleDocs = "https://docs.google.com/viewer?url="; 
           mWebView.loadUrl(googleDocs + url);

        }
        else
        {
            // Load all other urls normally.
            view.loadUrl(url);
        }

        return true;
     }

更新尝试此

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