阅读更多 原文地址: http://stackoverflow.com/a/31950789

@SuppressWarnings("deprecation")public static void clearCookies(Context context){    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {        Log.d(C.TAG, "Using clearCookies code for API >=" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));        CookieManager.getInstance().removeAllCookies(null);        CookieManager.getInstance().flush();    } else    {        Log.d(C.TAG, "Using clearCookies code for API <" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));        CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context);        cookieSyncMngr.startSync();        CookieManager cookieManager=CookieManager.getInstance();        cookieManager.removeAllCookie();        cookieManager.removeSessionCookie();        cookieSyncMngr.stopSync();        cookieSyncMngr.sync();    }}

I call this method in the following manner from my fragment:
mWebView.clearCache(true);mWebView.clearHistory();U.clearCookies(getActivity());mWebView.loadUrl(authorizeURL);

It is possible to dump the cookies for a domain before and after the call to clearCookies by:
String yahooCookies = CookieManager.getInstance().getCookie("https://yahoo.com");Log.d(C.TAG, "Cookies for yahoo.com:" + yahooCookies);

After calling clearCookies yahooCookies will be null.

This implementation feeds my needs, I have tested it on several emulators and a prehistoric Samsung Galaxy Gio with Android 2.3.3 and Nexus 5 with Android 5.1.1.

更多相关文章

  1. Android(安卓)播放视频的方法+播放测试地址 http
  2. Android(安卓)OKHTTP 网络请求出错重连---http拦
  3. 获得联系人姓名,相关电话以及邮件地址sdk2.0
  4. android POST请求
  5. android source code online
  6. Android(安卓)8.0无法调用Geocoder 中的getFromLocation()解决办
  7. Eclipse+android 开发配置步骤
  8. Android(安卓)常用开发框架
  9. Android(安卓)自定义下拉刷新上拉加载

随机推荐

  1. Android(安卓)下拉刷新控件的使用
  2. Android(安卓)横竖屏切换的Activity生命
  3. Android日常知识收集与总结之Android的Di
  4. 【Android(安卓)开发教程】屏幕方向的改
  5. android默认debug.keystore的密码
  6. 创建android逐帧动画的两种方式 布局和ja
  7. 关于android 经典蓝牙开发 使用UUID连接
  8. Java android ios 通用可逆des加密算法
  9. android性能测试工具Emmagee介绍
  10. android平台开发问题小结----今天遇到的