Search in sources :

Example 11 with CookieManager

use of android.webkit.CookieManager in project facebook-api-android-maven by avianey.

the class Utility method clearCookiesForDomain.

private static void clearCookiesForDomain(Context context, String domain) {
    // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager
    // has never been created.
    CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
    syncManager.sync();
    CookieManager cookieManager = CookieManager.getInstance();
    String cookies = cookieManager.getCookie(domain);
    if (cookies == null) {
        return;
    }
    String[] splitCookies = cookies.split(";");
    for (String cookie : splitCookies) {
        String[] cookieParts = cookie.split("=");
        if (cookieParts.length > 0) {
            String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;";
            cookieManager.setCookie(domain, newCookie);
        }
    }
    cookieManager.removeExpiredCookie();
}
Also used : CookieSyncManager(android.webkit.CookieSyncManager) CookieManager(android.webkit.CookieManager)

Example 12 with CookieManager

use of android.webkit.CookieManager in project AgentWeb by Justson.

the class AgentWebConfig method removeAllCookies.

public static void removeAllCookies(Context context) {
    if (CookieSyncManager.getInstance() == null)
        CookieSyncManager.createInstance(context);
    CookieManager cm = CookieManager.getInstance();
    cm.removeAllCookie();
}
Also used : CookieManager(android.webkit.CookieManager)

Example 13 with CookieManager

use of android.webkit.CookieManager in project AgentWeb by Justson.

the class AgentWebConfig method syncCookieToWebView.

/**
     *
     * okhttp
     *
     *
     */
public static void syncCookieToWebView(String url, String cookies) {
    CookieManager mCookieManager = CookieManager.getInstance();
    mCookieManager.setCookie(url, cookies);
}
Also used : CookieManager(android.webkit.CookieManager)

Example 14 with CookieManager

use of android.webkit.CookieManager in project android-app-common-tasks by multidots.

the class SocialAuthAdapter method signOut.

/**
     * Signs out the user out of current provider
     *
     * @return Status of signing out
     */
@SuppressWarnings("UnusedReturnValue")
public boolean signOut(Context ctx, String providerName) {
    // remove cookies
    Context appContext = ctx.getApplicationContext();
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    if (providerName != null) {
        if (socialAuthManager.getConnectedProvidersIds().contains(providerName))
            socialAuthManager.disconnectProvider(providerName);
        Editor edit = PreferenceManager.getDefaultSharedPreferences(appContext).edit();
        edit.remove(providerName + " key");
        edit.apply();
        Log.d("SocialAuthAdapter", "Disconnecting Provider");
        return true;
    } else {
        Log.d("SocialAuthAdapter", "The provider name should be same");
        return false;
    }
}
Also used : Context(android.content.Context) Editor(android.content.SharedPreferences.Editor) CookieManager(android.webkit.CookieManager)

Example 15 with CookieManager

use of android.webkit.CookieManager in project generic-oauth2-login-for-android by wareninja.

the class Utils method clearCookies.

public static void clearCookies(Context context) {
    // Edge case: an illegal state exception is thrown if an instance of 
    // CookieSyncManager has not be created.  CookieSyncManager is normally
    // created by a WebKit view, but this might happen if you start the 
    // app, restore saved state, and click logout before running a UI 
    // dialog in a WebView -- in which case the app crashes
    @SuppressWarnings("unused") CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
}
Also used : CookieSyncManager(android.webkit.CookieSyncManager) CookieManager(android.webkit.CookieManager)

Aggregations

CookieManager (android.webkit.CookieManager)36 CookieSyncManager (android.webkit.CookieSyncManager)9 Test (org.junit.Test)7 WebView (android.webkit.WebView)4 SuppressLint (android.annotation.SuppressLint)3 WebSettings (android.webkit.WebSettings)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Editor (android.content.SharedPreferences.Editor)2 Uri (android.net.Uri)2 View (android.view.View)2 WebViewClient (android.webkit.WebViewClient)2 TextView (android.widget.TextView)2 TargetApi (android.annotation.TargetApi)1 ActionBar (android.app.ActionBar)1 AlarmManager (android.app.AlarmManager)1 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1