WebViewClient onReceivedError deprecated, new version does not detect all errors

前端 未结 2 1895
时光取名叫无心
时光取名叫无心 2020-12-07 22:57

In the Android SDK 23 onReceivedError(WebView view, int errorCode, String description, String failingUrl) has been deprecated and replaced with onReceived

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 23:26

    You could also do following:

    @SuppressWarnings("deprecation")
    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        // Handle the error
    }
    
    @TargetApi(android.os.Build.VERSION_CODES.M)
    @Override
    public void onReceivedError(WebView view, WebResourceRequest req, WebResourceError rerr) {
        // Redirect to deprecated method, so you can use it in all SDK versions
        onReceivedError(view, rerr.getErrorCode(), rerr.getDescription().toString(), req.getUrl().toString());
    }
    

    Make sure you import android.annotation.TargetApi

    Happy coding!

提交回复
热议问题