當前位置: 首頁>>代碼示例>>Java>>正文


Java CookieManager類代碼示例

本文整理匯總了Java中android.webkit.CookieManager的典型用法代碼示例。如果您正苦於以下問題:Java CookieManager類的具體用法?Java CookieManager怎麽用?Java CookieManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CookieManager類屬於android.webkit包,在下文中一共展示了CookieManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: removeSessionCookies

import android.webkit.CookieManager; //導入依賴的package包/類
public static void removeSessionCookies(ValueCallback<Boolean> callback) {

        if (callback == null)
            callback = getDefaultIgnoreCallback();
        if (CookieManager.getInstance() == null) {
            callback.onReceiveValue(new Boolean(false));
            return;
        }
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            CookieManager.getInstance().removeSessionCookie();
            toSyncCookies();
            callback.onReceiveValue(new Boolean(true));
            return;
        }
        CookieManager.getInstance().removeSessionCookies(callback);
        toSyncCookies();

    }
 
開發者ID:Justson,項目名稱:AgentWeb,代碼行數:19,代碼來源:AgentWebConfig.java

示例2: clearCookiesForDomain

import android.webkit.CookieManager; //導入依賴的package包/類
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();
}
 
開發者ID:MobileDev418,項目名稱:AndroidBackendlessChat,代碼行數:24,代碼來源:Utility.java

示例3: reset

import android.webkit.CookieManager; //導入依賴的package包/類
public void reset() {
	Editor editor = mSharedPref.edit();
	
	editor.putString(ACCESS_TOKEN, 	"");
	editor.putString(USERID, 		"");
	editor.putString(USERNAME, 		"");
	editor.putString(FULLNAME, 		"");
	editor.putString(PROFILPIC, 	"");
	editor.putInt(FOLLOW,0);
	editor.putInt(FOLLOWED,0);
	
	editor.commit();
	
	CookieSyncManager.createInstance(mContext);
	
	CookieManager cookieManager = CookieManager.getInstance();
	cookieManager.removeAllCookie();
}
 
開發者ID:inceleb,項目名稱:InstagramManager-Android,代碼行數:19,代碼來源:InstagramSession.java

示例4: getCookieFromAppCookieManager

import android.webkit.CookieManager; //導入依賴的package包/類
public static String getCookieFromAppCookieManager(String url) throws MalformedURLException {
    CookieManager cookieManager = CookieManager.getInstance();
    if (cookieManager == null)
        return null;
    // 出錯點 1
    cookieManager.setAcceptCookie(true);
    String rawCookieHeader = null;
    URL parsedURL = new URL(url);

    // 出錯點 2
    // Extract Set-Cookie header value from Android app CookieManager for this URL
    rawCookieHeader = cookieManager.getCookie(parsedURL.getHost());
    if (rawCookieHeader == null)
        return null;
    return rawCookieHeader;
}
 
開發者ID:kamisakihideyoshi,項目名稱:TaipeiTechRefined,代碼行數:17,代碼來源:Connector.java

示例5: onPageFinished

import android.webkit.CookieManager; //導入依賴的package包/類
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);

    // CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager.getInstance().sync();
    }

    // https://issues.apache.org/jira/browse/CB-11248
    view.clearFocus();
    view.requestFocus();

    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);

        sendUpdate(obj, true);
    } catch (JSONException ex) {
        LOG.d(LOG_TAG, "Should never happen");
    }
}
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:25,代碼來源:InAppBrowser.java

示例6: clearCookiesForDomain

import android.webkit.CookieManager; //導入依賴的package包/類
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();
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:25,代碼來源:Utility.java

示例7: setCookie

import android.webkit.CookieManager; //導入依賴的package包/類
private void setCookie(Context context, String domain, String sessionCookie) {
    CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    if (sessionCookie != null) {
        // delete old cookies
        cookieManager.removeSessionCookie();
    }
    try {
        Thread.sleep(200);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    cookieManager.setCookie(domain, sessionCookie);

    CookieSyncManager.createInstance(context);
    CookieSyncManager.getInstance().sync();
}
 
開發者ID:dueros,項目名稱:dcs-sdk-java,代碼行數:19,代碼來源:BaseWebView.java

示例8: hasSession

import android.webkit.CookieManager; //導入依賴的package包/類
public static boolean hasSession() {
    if (!CookieManager.getInstance().hasCookies()) {
        return false;
    }
    String cookies = CookieManager.getInstance().getCookie("www.lostfilm.tv");
    if (cookies != null) {
        String[] cookieList = cookies.split(";");
        for (String cookie : cookieList) {
            String name = cookie.split("=")[0].trim();
            String value = cookie.split("=")[1].trim();
            if (name.equals("lf_session")) {
                return true;
            }
        }
    }

    return false;
}
 
開發者ID:CrazyDude1994,項目名稱:lostfilm-android-client,代碼行數:19,代碼來源:Utils.java

示例9: clearCookies

import android.webkit.CookieManager; //導入依賴的package包/類
/**
 * Clear the cookies
 */
@SuppressWarnings("deprecation")
public void clearCookies() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(getContext());
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}
 
開發者ID:vic797,項目名稱:prowebview,代碼行數:19,代碼來源:ProWebView.java

示例10: getExistingCookie

import android.webkit.CookieManager; //導入依賴的package包/類
private String getExistingCookie() {
    try {
        CookieSyncManager.createInstance(context);
        CookieManager cm = CookieManager.getInstance();
        if (cm != null) {
            String wvcookie = cm.getCookie(Settings.COOKIE_DOMAIN);
            if (!TextUtils.isEmpty(wvcookie)) {
                String[] existingCookies = wvcookie.split("; ");
                for (String cookie : existingCookies) {
                    if (cookie != null && cookie.contains(Settings.AN_UUID)) {
                        return cookie;
                    }
                }
            }
        }
    } catch (Exception e) {
    }
    return null;
}
 
開發者ID:prebid,項目名稱:prebid-mobile-android,代碼行數:20,代碼來源:ServerConnector.java

示例11: onCreate

import android.webkit.CookieManager; //導入依賴的package包/類
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mSpinner = new ProgressDialog(getContext());
  mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
  mSpinner.setMessage("Loading...");
  mContent = new LinearLayout(getContext());
  mContent.setOrientation(LinearLayout.VERTICAL);
  setUpTitle();
  setUpWebView();
  Display display = getWindow().getWindowManager().getDefaultDisplay();
  final float scale = getContext().getResources().getDisplayMetrics().density;
  float[] dimensions =
      (display.getWidth() < display.getHeight()) ? DIMENSIONS_PORTRAIT : DIMENSIONS_LANDSCAPE;
  addContentView(mContent, new FrameLayout.LayoutParams((int) (dimensions[0] * scale + 0.5f),
      (int) (dimensions[1] * scale + 0.5f)));
  CookieSyncManager.createInstance(getContext());
  CookieManager cookieManager = CookieManager.getInstance();
  cookieManager.removeAllCookie();
}
 
開發者ID:mukeshsolanki,項目名稱:social-login-helper,代碼行數:20,代碼來源:InstagramDialog.java

示例12: clearCookies

import android.webkit.CookieManager; //導入依賴的package包/類
/**
 * @see <a href="http://stackoverflow.com/questions/28998241/how-to-clear-cookies-and-cache-of-webview-on-android-when-not-in-webview" />
 * @param context
 */
@SuppressWarnings("deprecation")
public static void clearCookies(Context context)
{

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else
    {
        CookieSyncManager cookieSyncMngr= CookieSyncManager.createInstance(context);
        cookieSyncMngr.startSync();
        CookieManager cookieManager= CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}
 
開發者ID:TaRGroup,項目名稱:CoolApk-Console,代碼行數:23,代碼來源:Util.java

示例13: collectCookies

import android.webkit.CookieManager; //導入依賴的package包/類
@SuppressWarnings("deprecation")
private String[] collectCookies() {
    String cookies = CookieManager.getInstance().getCookie(Endpoints.BASE_URL);

    if (cookies == null || cookies.isEmpty()) {
        return null;
    }
    //See: http://stackoverflow.com/questions/28998241/how-to-clear-cookies-and-cache-of-webview-on-android-when-not-in-webview
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(getActivity().getApplicationContext());
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }

    return cookies.split(" ");
}
 
開發者ID:jam01,項目名稱:LittleLight,代碼行數:24,代碼來源:SignInFragment.java

示例14: removeSessionCookies

import android.webkit.CookieManager; //導入依賴的package包/類
public static void removeSessionCookies(ValueCallback<Boolean> callback) {

        if (callback == null)
            callback = getDefaultIgnoreCallback();
        if (CookieManager.getInstance() == null) {
            callback.onReceiveValue(new Boolean(false));
            return;
        }
        if (!SysUtils.hasLollipop()) {
            CookieManager.getInstance().removeSessionCookie();
            toSyncCookies();
            callback.onReceiveValue(new Boolean(true));
            return;
        } else {

            CookieManager.getInstance().removeSessionCookies(callback);
        }
        toSyncCookies();

    }
 
開發者ID:wzx54321,項目名稱:XinFramework,代碼行數:21,代碼來源:CookiesHandler.java

示例15: toSyncCookies

import android.webkit.CookieManager; //導入依賴的package包/類
private static void toSyncCookies() {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            CookieSyncManager.getInstance().sync();
            return;
        }

        AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
            @Override
            public void run() {
                if (SysUtils.hasLollipop())
                    CookieManager.getInstance().flush();

            }
        });
    }
 
開發者ID:wzx54321,項目名稱:XinFramework,代碼行數:17,代碼來源:CookiesHandler.java


注:本文中的android.webkit.CookieManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。