本文整理汇总了Java中android.webkit.CookieManager.flush方法的典型用法代码示例。如果您正苦于以下问题:Java CookieManager.flush方法的具体用法?Java CookieManager.flush怎么用?Java CookieManager.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.CookieManager
的用法示例。
在下文中一共展示了CookieManager.flush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeApp
import android.webkit.CookieManager; //导入方法依赖的package包/类
public static void closeApp (final Activity activity, WebView webView) {
sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
sharedPref.edit().putString("started", "").apply();
sharedPref.edit().putInt("closeApp", 1).apply();
if (sharedPref.getBoolean ("clearCookies", false)){
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookies(null);
cookieManager.flush();
}
if (sharedPref.getBoolean ("clearCache", false)){
webView.clearCache(true);
}
if (sharedPref.getBoolean ("clearForm", false)){
webView.clearFormData();
}
if (sharedPref.getBoolean ("history", false)){
activity.deleteDatabase("history_DB_v01.db");
webView.clearHistory();
}
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
activity.finish();
}
}, 500);
}
示例2: clearCookieByUrlInternal
import android.webkit.CookieManager; //导入方法依赖的package包/类
private static void clearCookieByUrlInternal(String url, CookieManager pCookieManager) {
if (TextUtils.isEmpty(url)) {
return;
}
String cookieString = pCookieManager.getCookie(url);
Vector<String> cookie = getCookieNamesByUrl(cookieString);
if (cookie == null || cookie.isEmpty()) {
return;
}
int len = cookie.size();
for (int i = 0; i < len; i++) {
pCookieManager.setCookie(url, cookie.get(i) + "=-1");
}
pCookieManager.flush();
}
示例3: httpCookieSync
import android.webkit.CookieManager; //导入方法依赖的package包/类
/**
* Synchronize the uuid2 cookie to the Webview Cookie Jar
* This is only done if there is no present cookie.
*
* @param headers headers to extract cookies from for syncing
*/
@SuppressWarnings("deprecation")
private void httpCookieSync(Map<String, List<String>> headers) {
if (headers == null || headers.isEmpty()) return;
CookieManager cm = CookieManager.getInstance();
if (cm == null) {
LogUtil.i(Settings.TAG, "Unable to find a CookieManager");
return;
}
try {
String existingUUID = getExistingCookie();
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
String key = entry.getKey();
// Only "Set-cookie" and "Set-cookie2" pair will be parsed
if (key != null && (key.equalsIgnoreCase(Settings.VERSION_ZERO_HEADER)
|| key.equalsIgnoreCase(Settings.VERSION_ONE_HEADER))) {
for (String cookieStr : entry.getValue()) {
if (!TextUtils.isEmpty(cookieStr) && cookieStr.contains(Settings.AN_UUID)) {
// pass uuid2 to WebView Cookie jar if it's empty or outdated
if (existingUUID == null || !cookieStr.contains(existingUUID)) {
cm.setCookie(Settings.COOKIE_DOMAIN, cookieStr);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// CookieSyncManager is deprecated in API 21 Lollipop
CookieSyncManager.createInstance(context);
CookieSyncManager csm = CookieSyncManager.getInstance();
if (csm == null) {
LogUtil.i(Settings.TAG, "Unable to find a CookieSyncManager");
return;
}
csm.sync();
} else {
cm.flush();
}
}
}
}
}
}
} catch (IllegalStateException ise) {
} catch (Exception e) {
}
}