【问题标题】:android internet connection error failsandroid互联网连接错误失败
【发布时间】:2015-10-24 08:52:11
【问题描述】:

您好,如果互联网连接失败,我会尝试向用户显示服装文件。在这种情况下,它工作正常。如果互联网连接正常并且index.php 被加载,那么在此之前一切正常。

如果我点击index.php 上的一个按钮,并且用户被重定向到另一个页面说我们login.php,则服装错误文件将启动。那很糟。 myerrorpage.html 文件如何只在网络连接失败而不是项目文件更改时才显示?

 @Override
public void onCreate(Bundle savedInstanceState) {


    setContentView(R.layout.activity_localy);
    mWebView = (WebView) findViewById(R.id.webview);
    // Brower niceties -- pinch / zoom, follow links in place
    mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    mWebView.setWebViewClient(new GeoWebViewClient());
    // Below required for geolocation
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setGeolocationEnabled(true);
    mWebView.setWebChromeClient(new GeoWebChromeClient());     
    // Load google.com
    mWebView.loadUrl("http://192./loc/index.php");

   super.onCreate(savedInstanceState); mWebView.setWebViewClient(new WebViewClient() {
   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            mWebView.loadUrl("file:///android_asset/myerrorpage.html");

        }
    }); 
}

【问题讨论】:

    标签: java android web-applications error-handling


    【解决方案1】:

    From,

    向主机应用程序报告 Web 资源加载错误。这些错误通常表示无法连接到服务器。请注意,与已弃用的回调版本不同,新版本将针对任何资源(iframe、图像等)调用,而不仅仅是主页。因此,建议在此回调中执行所需的最少工作。

    此方法不是检查 Internet 连接问题的最佳方法。您可以手动检查 Internet 连接并加载错误页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-24
      • 1970-01-01
      • 2015-09-12
      • 2010-12-16
      • 2015-06-03
      • 2014-07-21
      相关资源
      最近更新 更多