java Android Webview ERR_NAME_NOT_RESOLVED 加载 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33275717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 21:27:47  来源:igfitidea点击:

Android Webview ERR_NAME_NOT_RESOLVED loading an URL

javaandroidandroid-webview

提问by CoderRoller

I have an App made using Android Webview, while using Wifi connection the initial page loaded displays ok, after switching to mobile data mode, the application shows the ERR_NAME_NOT_RESOLVEDmessage at times.

我有一个使用 Android 制作的应用程序Webview,使用 Wifi 连接时,加载的初始页面显示正常,切换到移动数据模式后,应用程序ERR_NAME_NOT_RESOLVED有时会显示消息。

Is there a workaround to hide this message until the page is correctly displayed? or to make it work when the connection is not good in the initial load?

在页面正确显示之前是否有隐藏此消息的解决方法?或者在初始加载时连接不好时使其工作?

Thanks for the insight.

感谢您的洞察力。

回答by Ravneet Singh

You can check the url that is getting loaded in your webview by doing this.

您可以通过执行此操作检查在您的 webview 中加载的 url。

myWebView.setWebViewClient(new WebViewClient() {
    @SuppressLint("NewApi")
    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
    }
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);    
    }
});

回答by Jarvis

You can ask the user to retry at that point of time either displaying there or by showing a popup with a message. If you get the network is strong enough load the same page again.

您可以要求用户在那个时间点重试,要么显示在那里,要么显示带有消息的弹出窗口。如果您的网络足够强大,请再次加载同一页面。