diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/network/NetworkModule.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/network/NetworkModule.java index db18108e7b9..ebcc47d9562 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/network/NetworkModule.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/network/NetworkModule.java @@ -15,6 +15,7 @@ */ package com.tencent.mtt.hippy.modules.nativemodules.network; +import android.os.Build; import android.text.TextUtils; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; @@ -152,7 +153,7 @@ public void setCookie(String url, String keyValue, String expires) { saveCookie2Manager(url, keyValue); } - mCookieSyncManager.sync(); + syncCookie(); } } @@ -183,11 +184,18 @@ private static CookieManager getCookieManager() { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); - cookieManager.removeSessionCookie(); } return CookieManager.getInstance(); } + private static void syncCookie() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + CookieManager.getInstance().flush(); + } else if (mCookieSyncManager != null) { + mCookieSyncManager.sync(); + } + } + private static class HttpTaskCallbackImpl implements HippyHttpAdapter.HttpTaskCallback { private final Promise mPromise; @@ -236,7 +244,7 @@ public void onTaskSuccess(HippyHttpRequest request, HippyHttpResponse response) } } if (hasSetCookie) { - mCookieSyncManager.sync(); + syncCookie(); } }