android webview抓坏网址

 zhangmy0815522 发布于 2023-01-19 10:37

在我的应用程序中,我从Web服务接收URL作为字符串并将其加载到WebView.

mainContentText = (WebView) findViewById(R.id.mainContentText); 
mainContentText.getSettings().setJavaScriptEnabled(true);
mainContentText.setWebViewClient(new CustomWebClient());

mainContentText.loadUrl(url);

private class CustomWebClient extends WebViewClient{

        private static final String TAG = "WebWiewActivity";

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.d(TAG, "loading: " + url);
            return false;
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            Log.e(TAG, String.format("*ERROR*  Code: %d  Desc: %s  URL: %s", errorCode, description, failingUrl));
        }
    }

当测试的情况,当URL不好(一个随机字符串,url = "abc")我只是在收到默认的错误页面,但没有onReceivedErrorshouldOverrideUrlLoading回调并没有异常
我如何能赶上这样的情况?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有