Android Webview 有时无法呈现 pdf,而是显示空白/白页 [英] Android Webview cannot render the pdf sometimes and shows blank/white page instead

查看:42
本文介绍了Android Webview 有时无法呈现 pdf,而是显示空白/白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 使用谷歌文档在 webview 中打开 pdf
  • 一次又一次地打开相同的 pdf 或不同的 pdf.
  • 有时它会在 android 中显示空白/白色页面,直到我们再次刷新网页 1 或 2 次.

我已经在 pdf 上制作了样本.该项目的链接如下所示:

I have made the sample on the pdf. The link for the project is shown below:

https://github.com/gopalawasthi123/PdfWebView

希望这能更好地帮助您.

Hope this will help you Better.

public void SetWebView(WebView webview,string externalUrl){
            webview.Tag = "webview";
            webview.Settings.JavaScriptEnabled = true;
            webview.Settings.SupportZoom ();
            webview.Settings.SetAppCacheEnabled(true);
            webview.Settings.DomStorageEnabled = true;
            webview.ZoomOut ();
            webview.ZoomIn ();
            webview.Settings.BuiltInZoomControls = true;
            webview.Settings.LoadWithOverviewMode = true;
            webview.Settings.UseWideViewPort = true;
            //webview.Settings.SetSupportZoom (true);
            webview.Settings.SetPluginState (WebSettings.PluginState.On);
            webview.Settings.GetPluginState ();
            if (externalUrl.StartsWith("http://") || externalUrl.StartsWith("https://"))
                webview.LoadUrl (externalUrl);
            webview.SetWebViewClient (new MonkeyWebViewClient (imgViewBack, imgViewForward, imgRefresh));
            webview.SetWebChromeClient (new WebChromeClient ());
        }

推荐答案

您可以重新加载页面,直到它以这种方式显示 pdf:

You can reload the page until it displays the pdf in this way:

public void onPageFinished(WebView view, String url) {
if (view.getTitle().equals(""))
    view.reload();
}

这篇关于Android Webview 有时无法呈现 pdf,而是显示空白/白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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