从url查看Android Webview中的pdf文件

时间:2015-02-16 18:06:12

标签: android url pdf webview

我正在尝试通过此网址在Android WebView中打开pdf文件:

http://bijsluiters.fagg-afmps.be/registrationSearchServlet?key=BE-TU441865&leafletType=leafletNL

当我在网上搜索有关如何实现这一目标的信息时,我发现了这一点 你需要在它前面扩展这个网址:“http://docs.google.com/gview?embedded=true&url=

但是当我这样做时,我只能在浏览器中打开链接时看到html: “https://docs.google.com/gview?embedded=true&url=http://bijsluiters.fagg-afmps.be/registrationSearchServlet?key=BE-TU441865&leafletType=leafletNL

如何在网页浏览中查看实际的非HTML内容?

public class BijsluiterFragment : Android.Support.V4.App.Fragment
{
    //Title = DomainController.Instance.GetWord("BijsluiterTitle");
    private View view;
    private WebView webview;
    private string url;

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        view = inflater.Inflate (Resource.Layout.BijsluiterFragment, container, false);
        webview = view.FindViewById<WebView> (Resource.Id.webView);
        webview.Settings.JavaScriptEnabled=true;
        webview.Settings.SetPluginState (WebSettings.PluginState.On);
        if(!String.IsNullOrEmpty(url))
        {
            webview.LoadUrl ("http://docs.google.com/gview?embedded=true&url="+url);
        }
        return view;
    }

    public void SetUrl(string url)
    {
        this.url = url;
    }
}

我也试过'loadwithbaseurl'方法,但它也没有用...

1 个答案:

答案 0 :(得分:4)

我解决了同样的问题:

if (url.endsWith(".pdf")) {
    try {
         String urlEncoded = URLEncoder.encode(url, "UTF-8");
         url = "http://docs.google.com/viewer?url=" + urlEncoded;
    } catch (UnsupportedEncodingException e) {
         e.printStackTrace();
    }

}

使用此前缀:&#34; http://docs.google.com/viewer?url=&#34; WebView使用GoogleDocs打开pdf。

希望它可以帮到你!!