Skip to content

Commit 2341883

Browse files
feat(core): android cookie manager setup (NativeScript#10657)
1 parent f970455 commit 2341883

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/types-android/src/lib/android/org.nativescript.widgets.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
public error: java.lang.Exception;
7474
}
7575

76+
export function setCookieManager(cookieManager: java.net.CookieManager): void;
77+
export function initializeCookieManager(): java.net.CookieManager;
7678
export function MakeRequest(options: RequestOptions, callback: CompleteCallback, context: any);
7779
}
7880
}

packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/Async.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,32 @@ public static class Http {
297297
private static final String HEAD_METHOD = "HEAD";
298298
private static CookieManager cookieManager;
299299

300+
public static void setCookieManager(CookieManager manager) {
301+
if(manager == null) return;
302+
303+
cookieManager = manager;
304+
if (CookieHandler.getDefault() == null) {
305+
CookieHandler.setDefault(manager);
306+
}
307+
}
308+
309+
public static CookieManager initializeCookieManager() {
310+
if (cookieManager == null) {
311+
CookieHandler defaultHandler = CookieHandler.getDefault();
312+
if (defaultHandler instanceof CookieManager) {
313+
cookieManager = (CookieManager) defaultHandler;
314+
} else {
315+
cookieManager = new CookieManager();
316+
CookieHandler.setDefault(cookieManager);
317+
}
318+
}
319+
320+
return cookieManager;
321+
}
322+
300323
public static void MakeRequest(final RequestOptions options, final CompleteCallback callback, final Object context) {
301324
if (cookieManager == null) {
302-
cookieManager = new CookieManager();
303-
CookieHandler.setDefault(cookieManager);
325+
initializeCookieManager();
304326
}
305327

306328
final android.os.Handler mHandler = new android.os.Handler(Looper.myLooper());

0 commit comments

Comments
 (0)