Java Code Examples for android.webkit.CookieSyncManager#getInstance()

The following examples show how to use android.webkit.CookieSyncManager#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdActivity.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle b) {
    super.onCreate(b);

    String activityType = getIntent().
            getStringExtra(INTENT_KEY_ACTIVITY_TYPE);
    if (StringUtil.isEmpty(activityType)) {
        Clog.e(Clog.baseLogTag, Clog.getString(R.string.adactivity_no_type));
        finish();
    } else if (ACTIVITY_TYPE_INTERSTITIAL.equals(activityType)) {
        implementation = new InterstitialAdActivity(this);
        implementation.create();
    } else if (ACTIVITY_TYPE_BROWSER.equals(activityType)) {
        implementation = new BrowserAdActivity(this);
        implementation.create();
    } else if (ACTIVITY_TYPE_MRAID.equals(activityType)) {
        implementation = new MRAIDAdActivity(this);
        implementation.create();
    }

    CookieSyncManager.createInstance(this);
    CookieSyncManager csm = CookieSyncManager.getInstance();
    if (csm != null) csm.startSync();
}
 
Example 2
Source File: ThreadViewFragment.java    From something.apk with MIT License 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if(((MainActivity)getActivity()).isFragmentFocused(this)){
        threadView.onResume();
        threadView.resumeTimers();
        updateActionbarColor(forumId);
        setTitle(threadTitle);
    }
    CookieSyncManager cookieMan = CookieSyncManager.getInstance();
    if(cookieMan != null){
        cookieMan.startSync();
    }
}
 
Example 3
Source File: ThreadViewFragment.java    From something.apk with MIT License 5 votes vote down vote up
@Override
public void onPause() {
    super.onPause();
    threadView.pauseTimers();
    threadView.onPause();
    CookieSyncManager cookieMan = CookieSyncManager.getInstance();
    if(cookieMan != null){
        cookieMan.stopSync();
    }
}
 
Example 4
Source File: AdActivity.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPause() {
    if (implementation != null) {
        WebviewUtil.onPause(implementation.getWebView());
    }
    CookieSyncManager csm = CookieSyncManager.getInstance();
    if (csm != null) csm.stopSync();
    super.onPause();
}
 
Example 5
Source File: AdActivity.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    if (implementation != null) {
        WebviewUtil.onResume(implementation.getWebView());
    }
    CookieSyncManager csm = CookieSyncManager.getInstance();
    if (csm != null) csm.startSync();
    super.onResume();
}
 
Example 6
Source File: PrebidServerAdapter.java    From prebid-mobile-android with Apache License 2.0 4 votes vote down vote up
/**
 * 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("PrebidNewAPI", "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(PrebidServerSettings.VERSION_ZERO_HEADER)
                    || key.equalsIgnoreCase(PrebidServerSettings.VERSION_ONE_HEADER))) {
                for (String cookieStr : entry.getValue()) {
                    if (!TextUtils.isEmpty(cookieStr) && cookieStr.contains(PrebidServerSettings.AN_UUID)) {
                        // pass uuid2 to WebView Cookie jar if it's empty or outdated
                        if (existingUUID == null || !cookieStr.contains(existingUUID)) {
                            cm.setCookie(PrebidServerSettings.COOKIE_DOMAIN, cookieStr);
                            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                                // CookieSyncManager is deprecated in API 21 Lollipop
                                CookieSyncManager.createInstance(PrebidMobile.getApplicationContext());
                                CookieSyncManager csm = CookieSyncManager.getInstance();
                                if (csm == null) {
                                    LogUtil.i("Unable to find a CookieSyncManager");
                                    return;
                                }
                                csm.sync();
                            } else {
                                cm.flush();
                            }
                        }
                    }
                }
            }
        }
    } catch (IllegalStateException ise) {
    } catch (Exception e) {
    }
}
 
Example 7
Source File: CookieManagerCompat.java    From Android_Skin_2.0 with Apache License 2.0 4 votes vote down vote up
@Override
public void setAcceptCookie(Context context, boolean accept) {
	CookieSyncManager.getInstance();
	CookieManager.getInstance().setAcceptCookie(accept);
}
 
Example 8
Source File: WebviewUtil.java    From mobile-sdk-android with Apache License 2.0 4 votes vote down vote up
/**
 * 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")
public static void cookieSync(Map<String, List<String>> headers) {
    if (headers == null || headers.isEmpty()) return;
    CookieManager cm = CookieManager.getInstance();

    if (cm == null) {
       // Logger.i(Logger.LOGTAG, "Unable to find a CookieManager");
        return;
    }
    try {
        String existingUUID = getExistingANUUID();

        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(VERSION_ZERO_HEADER)
                    || key.equalsIgnoreCase(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.getCookieDomain(), cookieStr);

                            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                                // CookieSyncManager is deprecated in API 21 Lollipop
                                CookieSyncManager csm = CookieSyncManager.getInstance();
                                if (csm == null) {
                                    Clog.i(Clog.httpRespLogTag,"Unable to find a CookieSyncManager");
                                    return;
                                }
                                csm.sync();
                            } else {
                                cm.flush();
                            }
                        }
                    }
                }
            }
        }
    } catch (IllegalStateException ise) {
    } catch (Exception e) {
    }
}