首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BasicAuthentication for WebChromeClient

BasicAuthentication for WebChromeClient
EN

Stack Overflow用户
提问于 2015-06-10 08:59:59
回答 1查看 384关注 0票数 1

使用WebViewClient,我为BasicAuthentication使用了以下代码:

代码语言:javascript
复制
webView.loadUrl(url);
webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onReceivedHttpAuthRequest(WebView view,
                                              HttpAuthHandler handler, String host, String realm) {

            handler.proceed("test_user", "test_password");

        }

        //If you will not use this method url links are opeen in new brower not in webview
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

现在,我将WebChromeClient用作:

代码语言:javascript
复制
webView.loadUrl(url);
    webView.setWebChromeClient(new WebChromeClient() {

    });

在这种情况下,我该如何做BasicAuthentication?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-10 09:21:01

您需要同时使用两种方法:

代码语言:javascript
复制
webView.setWebChromeClient(new MyWebChromeClient());
webView.setWebViewClient(new WebViewClient() {

    @Override
    public void onReceivedHttpAuthRequest(WebView view,
                                          HttpAuthHandler handler, String host, String realm) {

        handler.proceed("test_user", "test_password");

    }

    //If you will not use this method url links are opeen in new brower not in webview
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
});
webView.loadUrl(url);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30751712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档