Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear logon credentials from WebView?

I want to clear application data like i can do it from settings. I need to clear login information in WebView when i am login to facebook or twitter, because when i log on once for each of the following uses the same data automatically

I try this: http://www.hrupin.com/2011/11/how-to-clear-user-data-in-your-android-application-programmatically

didn't work, login information are still in browser

I try reset app:

Intent i = getBaseContext().getPackageManager()
             .getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

also

@Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        view.clearCache(true);

        if(b){
            Log.d("WEBVIEW", "onFinisghed b true");
        Map<String, String> noCacheHeaders = new HashMap<String, String>(2);
        noCacheHeaders.put("Pragma", "no-cache");
        noCacheHeaders.put("Cache-Control", "no-cache");
        view.loadUrl(url, noCacheHeaders);
        b = false;
        }...

Most of the entries refers to the first method which is described in the link, but it does not work in my case, any ideas?

like image 372
user1861240 Avatar asked Jul 24 '13 21:07

user1861240


1 Answers

Try clearing the browser cookies. Logon credentials are often stored in browser cookies, which you can delete by a call to

CookieManager.getInstance().removeAllCookie();

Update:

CookieManager.getInstance().removeAllCookie() was deprecated in Android SDK 21 (Lollipop), and was replaced by CookieManager.getInstance().removeAllCookies(ValueCallback callback). As of November 2018, removeAllCookie() stills works as specified. Also, in the newer method removeAllCookies(ValueCallback callback), the callback function can be null if you don't want to be notified about removed cookies. Thus, it's safe to use

CookieManager.getInstance().removeAllCookies(null)

as a direct replacement for CookieManager.getInstance().removeAllCookie() when targeting devices after Android SDK 21.

CookieManager documentation is here.

like image 123
Yojimbo Avatar answered Nov 14 '22 21:11

Yojimbo