当前位置: 首页>>代码示例>>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;未经允许,请勿转载。