android.webkit.CookieManager Java Examples
The following examples show how to use
android.webkit.CookieManager.
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: PrebidServerAdapter.java From prebid-mobile-android with Apache License 2.0 | 6 votes |
private String getExistingCookie() { try { CookieSyncManager.createInstance(PrebidMobile.getApplicationContext()); CookieManager cm = CookieManager.getInstance(); if (cm != null) { String wvcookie = cm.getCookie(PrebidServerSettings.COOKIE_DOMAIN); if (!TextUtils.isEmpty(wvcookie)) { String[] existingCookies = wvcookie.split("; "); for (String cookie : existingCookies) { if (cookie != null && cookie.contains(PrebidServerSettings.AN_UUID)) { return cookie; } } } } } catch (Exception e) { } return null; }
Example #2
Source File: WebViewActivity.java From mattermost-android-classic with Apache License 2.0 | 6 votes |
private DownloadListener getDownloadListener() { return new DownloadListener() { public void onDownloadStart( String url, String userAgent, String contentDisposition, String mimetype, long contentLength ) { Uri uri = Uri.parse(url); Request request = new Request(uri); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setTitle("File download from Mattermost"); String cookie = CookieManager.getInstance().getCookie(url); if (cookie != null) { request.addRequestHeader("cookie", cookie); } DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); } }; }
Example #3
Source File: WebViewUtil.java From Huochexing12306 with Apache License 2.0 | 6 votes |
private static void saveCookie(String url){ String cookie = CookieManager.getInstance().getCookie(url); if(cookie !=null && !cookie.equals("")){ String[] cookies = cookie.split(";"); for(int i=0; i< cookies.length; i++){ String[] nvp = cookies[i].split("="); BasicClientCookie c = new BasicClientCookie(nvp[0], nvp[1]); //c.setVersion(0); c.setDomain("kyfw.12306.cn"); MyCookieStore myCookieStore = null; if (MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore() instanceof MyCookieStore){ myCookieStore = (MyCookieStore)MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore(); } if (myCookieStore != null){ myCookieStore.addCookie(c); } } } CookieSyncManager.getInstance().sync(); }
Example #4
Source File: AgentWebConfig.java From AgentWeb with Apache License 2.0 | 6 votes |
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(); }
Example #5
Source File: Utility.java From platform-friends-android with BSD 2-Clause "Simplified" License | 6 votes |
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(); }
Example #6
Source File: InAppBrowser.java From ultimate-cordova-webview-app with MIT License | 6 votes |
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"); } }
Example #7
Source File: InstagramDialog.java From social-login-helper-Deprecated- with MIT License | 6 votes |
@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(); }
Example #8
Source File: FacebookLoginActivity.java From facebooklogin with MIT License | 6 votes |
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(); }
Example #9
Source File: ACEWebView.java From appcan-android with GNU Lesser General Public License v3.0 | 6 votes |
public void init(EBrowserView eBrowserView) { mBroView = eBrowserView; mWebApp=true; if (Build.VERSION.SDK_INT <= 7) { if (mBaSetting == null) { mBaSetting = new EBrowserSetting(eBrowserView); mBaSetting.initBaseSetting(mWebApp); setWebViewClient(mEXWebViewClient = new CBrowserWindow()); setWebChromeClient(new CBrowserMainFrame(eBrowserView.getContext())); } } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ // 适配Android5.0无法正常保存和携带cookie的问题 CookieManager.getInstance().setAcceptThirdPartyCookies(this, true); } if (mBaSetting == null) { mBaSetting = new EBrowserSetting7(eBrowserView); mBaSetting.initBaseSetting(mWebApp); setWebViewClient(mEXWebViewClient = new CBrowserWindow7()); setWebChromeClient(new CBrowserMainFrame7(eBrowserView.getContext())); } } }
Example #10
Source File: MainActivity.java From Lucid-Browser with Apache License 2.0 | 6 votes |
/** * Clears browser cache etc */ protected void clearTraces(){ CustomWebView WV = webLayout.findViewById(R.id.browser_page); if (WV!=null){ WV.clearHistory(); WV.clearCache(true); } WebViewDatabase wDB = WebViewDatabase.getInstance(activity); wDB.clearFormData(); CookieSyncManager.createInstance(activity); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); // Usefull for future commits: // cookieManager.setAcceptCookie(false) // // WebView webview = new WebView(this); // WebSettings ws = webview.getSettings(); // ws.setSaveFormData(false); // ws.setSavePassword(false); // Not needed for API level 18 or greater (deprecat }
Example #11
Source File: Utility.java From barterli_android with Apache License 2.0 | 6 votes |
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(); }
Example #12
Source File: TorHelper.java From webTube with GNU General Public License v3.0 | 6 votes |
public void torEnable() { CookieHelper.acceptCookies(webView, false); CookieHelper.deleteCookies(); //Make sure that all cookies are really deleted if (!CookieManager.getInstance().hasCookies()) { if (!OrbotHelper.isOrbotRunning(mApplicationContext)) OrbotHelper.requestStartTor(mApplicationContext); try { WebkitProxy.setProxy(MainActivity.class.getName(), mApplicationContext, null, "localhost", PORT_TOR); SharedPreferences.Editor spEdit = sp.edit(); spEdit.putBoolean(PREF_TOR_ENABLED, true); spEdit.apply(); } catch (Exception e) { e.printStackTrace(); } } webView.reload(); }
Example #13
Source File: Utility.java From kognitivo with Apache License 2.0 | 6 votes |
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(); }
Example #14
Source File: WebViewUtils.java From android-auth with Apache License 2.0 | 6 votes |
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(); }
Example #15
Source File: HttpTask.java From letv with Apache License 2.0 | 6 votes |
protected void sendResponseMessage(HttpResponse response) { super.sendResponseMessage(response); Header[] headers = response.getHeaders("Set-Cookie"); if (headers != null && headers.length > 0) { CookieSyncManager.createInstance(LemallPlatform.getInstance().getContext()).sync(); CookieManager instance = CookieManager.getInstance(); instance.setAcceptCookie(true); instance.removeSessionCookie(); String mm = ""; for (Header header : headers) { String[] split = header.toString().split("Set-Cookie:"); EALogger.i("游客登录", "split[1]===>" + split[1]); instance.setCookie(Constants.GUESTLOGIN, split[1]); int index = split[1].indexOf(";"); if (TextUtils.isEmpty(mm)) { mm = split[1].substring(index + 1); EALogger.i("正式登录", "mm===>" + mm); } } EALogger.i("游客登录", "split[11]===>COOKIE_DEVICE_ID=" + LemallPlatform.getInstance().uuid + ";" + mm); instance.setCookie(Constants.GUESTLOGIN, "COOKIE_DEVICE_ID=" + LemallPlatform.getInstance().uuid + ";" + mm); instance.setCookie(Constants.THIRDLOGIN, "COOKIE_APP_ID=" + LemallPlatform.getInstance().getmAppInfo().getId() + ";" + mm); CookieSyncManager.getInstance().sync(); this.val$iLetvBrideg.reLoadWebUrl(); } }
Example #16
Source File: GDrive2020.java From xGetter with Apache License 2.0 | 6 votes |
private static void out(String result){ destroyWebView(); if (result!=null){ ArrayList<XModel> xModels = new ArrayList<>(); try { JSONArray jsonArray = new JSONArray(result); for(int i=0;i<jsonArray.length();i++){ String url = jsonArray.getJSONObject(i).getString("file"),quality = jsonArray.getJSONObject(i).getString("label"),cookies = CookieManager.getInstance().getCookie(url); XModel model = new XModel(); model.setUrl(url); model.setQuality(quality); model.setCookie(cookies); xModels.add(model); } } catch (JSONException e) { e.printStackTrace(); } onTaskCompleted.onTaskCompleted(Utils.sortMe(xModels),true); }else onTaskCompleted.onError(); }
Example #17
Source File: Session.java From kakao-android-sdk-standalone with Apache License 2.0 | 6 votes |
/** * 세션을 close하여 처음부터 새롭게 세션 open을 진행한다. * @param kakaoException exception이 발생하여 close하는 경우 해당 exception을 넘긴다. * @param forced 강제 close 여부. 강제 close이면 이미 close가 되었어도 callback을 호출한다. */ private void internalClose(final KakaoException kakaoException, final boolean forced) { synchronized (INSTANCE_LOCK) { final SessionState previous = state; state = SessionState.CLOSED; requestType = null; authorizationCode = AuthorizationCode.createEmptyCode(); accessToken = AccessToken.createEmptyToken(); onStateChange(previous, state, requestType, kakaoException, forced); } if (this.appCache != null) { this.appCache.clearAll(); } // 해당 도메인 cookie만 지우려고 했으나 CookieManager가 관리하는 cookie가 한 app에 대한 cookie여서 모두 날려도 되겠다. // CookieManager를 쓰려면 CookieSyncManager를 만들어야 하는 버그가 있다. CookieSyncManager.createInstance(context.getApplicationContext()); CookieManager.getInstance().removeAllCookie(); }
Example #18
Source File: WebViewActivity.java From pre-dem-android with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //清除cookie CookieSyncManager.createInstance(WebViewActivity.this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); setContentView(R.layout.activity_webview); mWebView = (WebView) findViewById(R.id.login_webview); mIntent = getIntent(); mUrl = mIntent.getStringExtra("extr_url"); mProgress = (ProgressBar) findViewById(R.id.login_webview_progress); init(); }
Example #19
Source File: MainActivity.java From Xndroid with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public Completable updateCookiePreference() { return Completable.create(new CompletableAction() { @Override public void onSubscribe(@NonNull CompletableSubscriber subscriber) { CookieManager cookieManager = CookieManager.getInstance(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { CookieSyncManager.createInstance(MainActivity.this); } cookieManager.setAcceptCookie(mPreferences.getCookiesEnabled()); subscriber.onComplete(); } }); }
Example #20
Source File: CookieKeeper.java From Simpler with Apache License 2.0 | 5 votes |
/** * 将cookie同步到WebView * * @param url WebView要加载的url * @param cookie 要同步的cookie * @return true:同步cookie成功;false:同步cookie失败 */ public static boolean syncCookie(Context context, String url, String cookie) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { CookieSyncManager.createInstance(context); } CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setCookie(url, cookie); String newCookie = cookieManager.getCookie(url); return !TextUtils.isEmpty(newCookie); }
Example #21
Source File: SyncUserStateUtil.java From letv with Apache License 2.0 | 5 votes |
public static void setGameTokenCookie(Context context, String token) { CookieSyncManager syncManger = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.setCookie("http://api.game.letvstore.com", "sso_tk=" + token); syncManger.sync(); LogInfo.log("wlx", "game cookie = " + cookieManager.getCookie("http://api.game.letvstore.com")); }
Example #22
Source File: ClassicWebViewProvider.java From focus-android with Mozilla Public License 2.0 | 5 votes |
/** * A cleanup that should occur when a new browser session starts. This might be able to be merged with * {@link #performCleanup(Context)}, but I didn't want to do it now to avoid unforeseen side effects. We can do this * when we rethink our erase strategy: #1472. * * This function must be called before WebView.loadUrl to avoid erasing current session data. */ public void performNewBrowserSessionCleanup() { // If the app is closed in certain ways, WebView.cleanup will not get called and we don't clear cookies. CookieManager.getInstance().removeAllCookies(null); // We run this on the main thread to guarantee it occurs before loadUrl so we don't erase current session data. final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); // When left open on erase, some pages, like the google search results, will asynchronously write LocalStorage // files to disk after we erase them. To work-around this, we delete this data again when starting a new browser session. WebStorage.getInstance().deleteAllData(); StrictMode.setThreadPolicy(oldPolicy); }
Example #23
Source File: WebViewHelper.java From Android_Skin_2.0 with Apache License 2.0 | 5 votes |
public static void setCookie(Context context, String url, String value) { if (context != null) { CookieSyncManager.createInstance(context); CookieManager.getInstance().setCookie(url, value); CookieSyncManager.getInstance().sync(); } }
Example #24
Source File: SystemDeviceModule.java From dcs-sdk-java with Apache License 2.0 | 5 votes |
private void handleThrowException(Directive directive) { Payload payload = directive.getPayload(); if (payload instanceof ThrowExceptionPayload) { ThrowExceptionPayload throwExceptionPayload = (ThrowExceptionPayload) payload; if (throwExceptionPayload.getCode() == ThrowExceptionPayload.Code.UNAUTHORIZED_REQUEST_EXCEPTION) { // 分别清空token 和 cookie OauthPreferenceUtil.clearAllOauth(DcsSampleApplication.getInstance()); HttpConfig.setAccessToken(""); CookieSyncManager.createInstance(DcsSampleApplication.getInstance()); CookieManager.getInstance().removeAllCookie(); } fireThrowException(throwExceptionPayload); } }
Example #25
Source File: MainActivity.java From Android-SmartWebView with MIT License | 5 votes |
public String fcm_token(){ FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( MainActivity.this, instanceIdResult -> { fcm_token = instanceIdResult.getToken(); if(true_online) { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.setCookie(ASWV_URL, "FCM_TOKEN="+fcm_token); Log.d("FCM_BAKED","YES"); //Log.d("COOKIES: ", cookieManager.getCookie(ASWV_URL)); } Log.d("REQ_FCM_TOKEN", fcm_token); }).addOnFailureListener(e -> Log.d("REQ_FCM_TOKEN", "FAILED")); return fcm_token; }
Example #26
Source File: AgentWebConfig.java From AgentWeb with Apache License 2.0 | 5 votes |
public static void removeAllCookies(@Nullable ValueCallback<Boolean> callback) { if (callback == null) { callback = getDefaultIgnoreCallback(); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().removeAllCookie(); toSyncCookies(); callback.onReceiveValue(!CookieManager.getInstance().hasCookies()); return; } CookieManager.getInstance().removeAllCookies(callback); toSyncCookies(); }
Example #27
Source File: ForwardingCookieHandler.java From react-native-GPay with MIT License | 5 votes |
/** * Instantiating CookieManager in KitKat+ will load the Chromium task taking a 100ish ms so we * do it lazily to make sure it's done on a background thread as needed. */ private CookieManager getCookieManager() { if (mCookieManager == null) { possiblyWorkaroundSyncManager(mContext); mCookieManager = CookieManager.getInstance(); if (USES_LEGACY_STORE) { mCookieManager.removeExpiredCookie(); } } return mCookieManager; }
Example #28
Source File: SystemCookieManager.java From cordova-plugin-intent with MIT License | 5 votes |
public SystemCookieManager(WebView webview) { webView = webview; cookieManager = CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.setAcceptThirdPartyCookies(webView, true); } }
Example #29
Source File: WebViewCookieJar.java From alpha-wallet-android with MIT License | 5 votes |
public WebViewCookieJar() { try { webViewCookieManager = CookieManager.getInstance(); } catch (Exception ex) { /* Caused by android.content.pm.PackageManager$NameNotFoundException com.google.android.webview */ } }
Example #30
Source File: UploadActivity.java From JayPS-AndroidApp with MIT License | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.delete_cookies: { CookieSyncManager.createInstance(getActivity()); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); return true; } default: { return super.onOptionsItemSelected(item); } } }