Android WebView清除基本身份验证凭据

Android WebView清除基本身份验证凭据,android,caching,webview,basic-authentication,webviewclient,Android,Caching,Webview,Basic Authentication,Webviewclient,我制作了一个应用程序,使用基本身份验证与服务器进行身份验证。但是,我无法清除凭据,因此这意味着我有两个未解决的问题: 用户不能在不退出程序的情况下注销 如果用户输入的凭据错误,他们必须退出并重新进入程序 我自己也尝试过很多不同的实现,很多都是在这个网站上推荐的。我在freenode上露营了#android开发人员,但没有用。这是我最后的选择 下面是我的WebView示例代码(我已经拿出了一些东西,但主要代码基本相同): 只有在我第一次运行它时,它才会在ReceivedHttPauthRequ

我制作了一个应用程序,使用基本身份验证与服务器进行身份验证。但是,我无法清除凭据,因此这意味着我有两个未解决的问题:

  • 用户不能在不退出程序的情况下注销
  • 如果用户输入的凭据错误,他们必须退出并重新进入程序
我自己也尝试过很多不同的实现,很多都是在这个网站上推荐的。我在freenode上露营了#android开发人员,但没有用。这是我最后的选择

下面是我的WebView示例代码(我已经拿出了一些东西,但主要代码基本相同):

只有在我第一次运行它时,它才会在ReceivedHttPauthRequest上运行。如果我注销并重新登录,它将使用以前的凭据运行onPageStarted和onPageFinished。因此,如果我注销并输入一个新用户,我将与原始用户一起重新登录。或者,如果我输入了错误的用户名和密码,它将挂在OnPageStarted上。我也尝试过使用onReceivedError和http错误,但没有任何好处

下面是我试图用logout()方法进行反授权的一些代码,以及代码的其他部分。我也尝试过许多不同的版本:

    wv.clearCache(true);
    wv.setHttpAuthUsernamePassword(host, realm, "","");
    clearCacheFolder(this.getCacheDir());
    clearCacheFolder(this.getExternalCacheDir());
    this.getBaseContext().deleteDatabase("webview.db");
    this.getBaseContext().deleteDatabase("webviewCache.db");
    WebViewDatabase.getInstance(getBaseContext()).clearHttpAuthUsernamePassword();
    WebViewDatabase.getInstance(getBaseContext()).clearUsernamePassword();
    WebViewDatabase.getInstance(getBaseContext()).clearFormData();
    WebStorage.getInstance().deleteAllData();
    wv.setHttpAuthUsernamePassword(host, realm,
    username, password);
ClearCacheFolder引用了markjan在此处发布的方法:

尝试以下操作:

    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

我在VKontakte登录活动中使用它来清除webview中保存的用户名/密码。

谢谢您的建议,但基本身份验证不使用cookies。尽管如此,我还是试过了。
@Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
    count++;
    if (count >= 3) {
    handler.cancel();// after adding this line of code my
                     //problem is solved. Hope it will for you too.

    Toast.makeText(getBaseContext(), "Login Failed. Please Try Again.", Toast.LENGTH_LONG).show();

    } else {
        handler.proceed(getUser(), getPass());
        }// end else
    }
@Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
    count++;
    if (count >= 3) {
    handler.cancel();// after adding this line of code my
                     //problem is solved. Hope it will for you too.

    Toast.makeText(getBaseContext(), "Login Failed. Please Try Again.", Toast.LENGTH_LONG).show();

    } else {
        handler.proceed(getUser(), getPass());
        }// end else
    }