简体   繁体   English

Android TV onReceivedError测试

[英]Android tv testing onReceivedError

I use a web view in my Android TV app and have handlers attached to it like: 我在Android TV应用中使用网络视图,并附加了以下处理程序:

        webView.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(context, "Oh no! " + description, Toast.LENGTH_SHORT).show();
            webView.loadUrl("file:///android_asset/error.html");
        }
    });

How would I go about testing this? 我将如何进行测试?

onReceivedError: onReceivedError:

This method was deprecated in API level 23. API级别23中不推荐使用此方法。

you should to use 你应该使用

void onReceivedError (WebView view, 
                WebResourceRequest request, 
                WebResourceError error)

onReceivedError in android docs Android文档中的onReceivedError

If you want to test the error case, try to connect a unknown web page, for example: http://google.com/404 如果要测试错误情况,请尝试连接未知的网页,例如: http : //google.com/404

run this code after creating and initializing the webview object 在创建并初始化webview对象后运行此代码

webView.loadUrl("http://google.com/404");

I hope this code will trigger the onReceivedError function 我希望这段代码将触发onReceivedError函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM