Skip to content

Instantly share code, notes, and snippets.

@rmkrishna
Created July 20, 2017 10:55
Show Gist options
  • Save rmkrishna/2a76db5ae5d98dcf588e92e657d4fe4d to your computer and use it in GitHub Desktop.
Save rmkrishna/2a76db5ae5d98dcf588e92e657d4fe4d to your computer and use it in GitHub Desktop.
Clear cache from CookieManager android
public class WebUtil {
public static 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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment