本文整理匯總了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();
}
示例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();
}
示例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();
}
示例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;
}
示例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");
}
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
}
示例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;
}
示例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();
}
示例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();
}
}
示例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(" ");
}
示例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();
}
示例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();
}
});
}