Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear cookies in Android

Tags:

android

How can I clear all cookies in android ?

Any sample code provided will be really helpful.

like image 505
peterlawn Avatar asked Nov 28 '22 03:11

peterlawn


2 Answers

    CookieSyncManager.createInstance(this); 
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookies(callback);
like image 119
Cassio Landim Avatar answered Nov 30 '22 22:11

Cassio Landim


@SuppressWarnings("deprecation")
public void clearCookies(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { 
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager cookieSyncMngr= CookieSyncManager.createInstance(context);
        cookieSyncMngr.startSync();
        CookieManager cookieManager= CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}
like image 30
Daniil Pavlenko Avatar answered Dec 01 '22 00:12

Daniil Pavlenko