使用WebViewClient,我使用以下代码进行BasicAuthentication:
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
作为:
webView.loadUrl(url);
webView.setWebChromeClient(new WebChromeClient() {
});
在这种情况下如何进行BasicAuthentication?
答案 0 :(得分:1)
您需要同时使用:
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);