WebViewでBasic認証のページにアクセスする

WebViewClient#onReceivedHttpAuthRequest() を実装する。


private final String USERNAME = "user";
private final String PASSWORD = "pass";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

WebView webView = (WebView)findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient(){
@Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
handler.proceed(USERNAME, PASSWORD);
}
});
}