0

我已经制作了一个经过身份验证的搜索 webview,它在登录时通过用户名和密码进行身份验证。每次我通过搜索在 webview 上时,它都会弹出已登录用户的身份验证消息(我相信是错误代码 410)。我如何压制或隐藏它?

我应该使用以下代码吗?

public void onReceivedError( WebView view, int errorCode, String description, String failingUrl ) {
    Toast.makeText(view.getContext(), "Authentication Error", Toast.LENGTH_LONG).show();

    if (errorCode == 410) {
        //webview.setHttpAuthUsernamePassword(host, realm, username, password);
        // Show alert to enter username and password.
        // Then, when those are entered in the alert,
        // set it through the setHttpAuthUsernamePassword(...)
        // shown below and then reload the site.
    }
    super.onReceivedError(view, errorCode, description, failingUrl);
}

如果是这样,我该如何用代码抑制或隐藏弹出窗口?

4

1 回答 1

0

将以下实现的onReceivedHttpAuthRequest方法添加到您的 WebViewClient 类:

....

    public void onReceivedError( WebView view, int errorCode, String description, String failingUrl ) {
        ....
    }

    @Override
    public void onReceivedHttpAuthRequest( WebView view, final HttpAuthHandler handler, final String host, final String realm) {
            // Replace SAVED_USERNAME and SAVED_PASSWORD with your authentication details.
            handler.proceed(SAVED_USERNAME,SAVED_PASSWORD);
    }

}

请参阅onReceivedHttpAuthRequest 的文档页面

于 2013-09-30T21:10:23.267 回答