I am using a webview based application where I am browsing the url in webview. Url has HTTP authentication.
When I run the URL for the first time, its onReceivedHttpAuthRequest () is called, and I show a dialog box for the user to enter authentication credentials, which are the username and password of the authentication.
@Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
final WebView mView = view;
final HttpAuthHandler mHandler = handler;
final EditText usernameInput = new EditText(mActivity);
usernameInput.setHint("Username");
final EditText passwordInput = new EditText(mActivity);
passwordInput.setHint("Password");
passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
LinearLayout ll = new LinearLayout(mActivity);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(usernameInput);
ll.addView(passwordInput);
Builder authDialog = new AlertDialog
.Builder(mActivity)
.setTitle("Authentication")
.setView(ll)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
mHandler.proceed(usernameInput.getText().toString(), passwordInput.getText().toString());
dialog.dismiss();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
mView.stopLoading();
onLoadListener.onAuthCancel((MyWebView)mView, mTitleTextView);
}
});
if(view!=null)
authDialog.show();
}
On The request is sent correctly and the URL is loaded. But after I exit the application using the back button (I do not send it in the background), if I run it again and return it to load the same url, it directly loads the URL without asking for credentials that onReceivedHttpAuthRequest () is no longer called.
, :
WebViewDatabase webDB = WebViewDatabase.getInstance(BrowserActivity.this);
if(webDB!=null){
if(webDB.hasFormData())
webDB.clearFormData();
if(webDB.hasUsernamePassword())
webDB.clearUsernamePassword();
if(webDB.hasHttpAuthUsernamePassword())
webDB.clearHttpAuthUsernamePassword();
}
webView.clearCache(true);
-, cookie webview:
BrowserActivity.this.deleteDatabase("webview.db");
BrowserActivity.this.deleteDatabase("webviewCache.db");
, . -, .
, , onReceivedHttpAuthRequest() ?