[转] How to clear cookies and cache of webview on Android(安卓)when not in webview?
16lz
2021-01-24
阅读更多 原文地址: http://stackoverflow.com/a/31950789
I call this method in the following manner from my fragment:
It is possible to dump the cookies for a domain before and after the call to clearCookies by:
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.
@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.
更多相关文章
- Android(安卓)播放视频的方法+播放测试地址 http
- Android(安卓)OKHTTP 网络请求出错重连---http拦
- 获得联系人姓名,相关电话以及邮件地址sdk2.0
- android POST请求
- android source code online
- Android(安卓)8.0无法调用Geocoder 中的getFromLocation()解决办
- Eclipse+android 开发配置步骤
- Android(安卓)常用开发框架
- Android(安卓)自定义下拉刷新上拉加载