In my application, I use WebView with WebViewClient, with overriden method onReceivedHttpAuthRequest, where I prompt user to enter his credentials, using AlertDialog. When credentials are entered, I call
handler.proceed(username, password);
My problem is: In Android 4 emulator, everything works fine, user can navigate through authenticated sites without any problem, but in older Android versions, it seems that onReceivedHttpAuthRequest is called each time when user refreshes, or navigates to another page within authenticated site.
Can someone please suggest me, what am I doing wrong? Thank you.
What I tried:
Calling also
webView.setHttpAuthUsernamePassword(host, realm, username, password);
when credentials are entered and adding this piece of code before invoking login dialog in onReceivedHttpAuthRequest:
String[] usernamePassword = webView.getHttpAuthUsernamePassword(host, realm);
if (usernamePassword!=null) {
handler.proceed(usernamePassword[0], usernamePassword[1]);
return;
}
did not work for me - user can navigate through authenticated sites, but after logout, username and password are still stored in webView and user is logged-in automatically again - in this case I need to detect user's logout and remove stored credentials, can somebody tell me, how to do this?
Many thanks!