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 Project: xGetter   Author: KhunHtetzNaing   File: GDrive2020.java    License: Apache License 2.0 6 votes vote down vote up
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 #2
Source Project: Lucid-Browser   Author: powerpoint45   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
	 * 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 #3
Source Project: mattermost-android-classic   Author: mattermost   File: WebViewActivity.java    License: Apache License 2.0 6 votes vote down vote up
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 #4
Source Project: facebooklogin   Author: greenhalolabs   File: FacebookLoginActivity.java    License: MIT License 6 votes vote down vote up
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 #5
Source Project: kakao-android-sdk-standalone   Author: kkung   File: Session.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 세션을 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 #6
Source Project: pre-dem-android   Author: pre-dem   File: WebViewActivity.java    License: MIT License 6 votes vote down vote up
@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 #7
Source Project: kognitivo   Author: eviltnan   File: Utility.java    License: Apache License 2.0 6 votes vote down vote up
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 #8
Source Project: ultimate-cordova-webview-app   Author: nioperas06   File: InAppBrowser.java    License: MIT License 6 votes vote down vote up
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 #9
Source Project: platform-friends-android   Author: telerik   File: Utility.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 #10
Source Project: appcan-android   Author: AppCanOpenSource   File: ACEWebView.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #11
Source Project: social-login-helper-Deprecated-   Author: mukeshsolanki   File: InstagramDialog.java    License: MIT License 6 votes vote down vote up
@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 #12
Source Project: Huochexing12306   Author: SShineTeam   File: WebViewUtil.java    License: Apache License 2.0 6 votes vote down vote up
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 #13
Source Project: AgentWeb   Author: Justson   File: AgentWebConfig.java    License: Apache License 2.0 6 votes vote down vote up
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 #14
Source Project: barterli_android   Author: barterli   File: Utility.java    License: Apache License 2.0 6 votes vote down vote up
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 #15
Source Project: webTube   Author: martykan   File: TorHelper.java    License: GNU General Public License v3.0 6 votes vote down vote up
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 #16
Source Project: prebid-mobile-android   Author: prebid   File: PrebidServerAdapter.java    License: Apache License 2.0 6 votes vote down vote up
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 #17
Source Project: android-auth   Author: spotify   File: WebViewUtils.java    License: Apache License 2.0 6 votes vote down vote up
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 #18
Source Project: letv   Author: JackChan1999   File: HttpTask.java    License: Apache License 2.0 6 votes vote down vote up
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 #19
Source Project: JayPS-AndroidApp   Author: team-mount-ventoux   File: UploadActivity.java    License: MIT License 5 votes vote down vote up
@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);
        }
    }
}
 
Example #20
Source Project: talk-android   Author: jianliaoim   File: TalkClient.java    License: MIT License 5 votes vote down vote up
@Override
public Throwable handleError(RetrofitError cause) {
    if (cause.getResponse() == null) {
        return new NetworkConnectedException("no network connected, please check network connected");
    }
    int code = cause.getResponse().getStatus();
    if (code == 403) {
        ErrorResponseData errorBoyd = (ErrorResponseData) cause.getBodyAs(ErrorResponseData.class);
        if (errorBoyd != null) {
            if (errorBoyd.code == 201 || errorBoyd.code == 220) {
                RealmConfig.deleteRealm();
                MainApp.PREF_UTIL.clear();
                CookieManager cookieManager = CookieManager.getInstance();
                cookieManager.removeAllCookie();
                NotificationUtil.stopPush(MainApp.CONTEXT);
                Intent intent = new Intent(MainApp.CONTEXT, Oauth2Activity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                BizLogic.cancelSync();
                MainApp.CONTEXT.startActivity(intent);

                // disconnect message service
                Intent closeMsgIntent = new Intent(MainApp.CONTEXT, MessageService.class);
                closeMsgIntent.setAction(MessageService.ACTION_CLOSE);
                MainApp.CONTEXT.startService(closeMsgIntent);
            }
        }
    }
    return cause;
}
 
Example #21
Source Project: xGetter   Author: KhunHtetzNaing   File: GPhotosUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static void putModel(String url, String quality, ArrayList<XModel> model){
    for (XModel x:model){
        if (x.getQuality().equalsIgnoreCase(quality)){
            return;
        }
    }
    if (url!=null && quality!=null) {
        XModel xModel = new XModel();
        xModel.setUrl(url);
        xModel.setQuality(quality);
        xModel.setCookie(CookieManager.getInstance().getCookie(url));
        model.add(xModel);
    }
}
 
Example #22
Source Project: MiBandDecompiled   Author: vishnudevk   File: SDK2APPReceiver.java    License: Apache License 2.0 5 votes vote down vote up
public void onReceive(Context context, Intent intent)
{
    CookieSyncManager.createInstance(context);
    String s = CookieManager.getInstance().getCookie("https://account.xiaomi.com");
    if (!TextUtils.isEmpty(s) && s.contains("userId=") && s.contains("passToken="))
    {
        String s1 = intent.getStringExtra("user_id");
        if (TextUtils.isEmpty(s1) || s1.equals(a(s)))
        {
            Intent intent1 = new Intent(APP2SDKReceiver.AUTH_ACTION_NAME);
            intent1.putExtra("pkg", context.getPackageName());
            context.sendBroadcast(intent1);
        }
    }
}
 
Example #23
Source Project: focus-android   Author: mozilla-mobile   File: ClassicWebViewProvider.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void applyAppSettings(@NotNull Context context, @NotNull WebSettings webSettings, @NotNull SystemWebView systemWebView) {

    // Clear the cache so trackers previously loaded are removed
    systemWebView.clearCache(true);

    // We could consider calling setLoadsImagesAutomatically() here too (This will block images not loaded over the network too)
    webSettings.setBlockNetworkImage(Settings.getInstance(context).shouldBlockImages());
    webSettings.setJavaScriptEnabled(!Settings.getInstance(context).shouldBlockJavaScript());
    CookieManager.getInstance().setAcceptThirdPartyCookies(systemWebView, !Settings.getInstance
            (context).shouldBlockThirdPartyCookies());
    CookieManager.getInstance().setAcceptCookie(!Settings.getInstance(context)
            .shouldBlockCookies());
}
 
Example #24
Source Project: zxingfragmentlib   Author: mitoyarzun   File: SearchBookContentsActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle icicle) {
  super.onCreate(icicle);

  // Make sure that expired cookies are removed on launch.
  CookieSyncManager.createInstance(this);
  CookieManager.getInstance().removeExpiredCookie();

  Intent intent = getIntent();
  if (intent == null || !intent.getAction().equals(Intents.SearchBookContents.ACTION)) {
    finish();
    return;
  }

  isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN);
  if (LocaleManager.isBookSearchUrl(isbn)) {
    setTitle(getString(R.string.sbc_name));
  } else {
    setTitle(getString(R.string.sbc_name) + ": ISBN " + isbn);
  }

  setContentView(R.layout.search_book_contents);
  queryTextView = (EditText) findViewById(R.id.query_text_view);

  String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY);
  if (initialQuery != null && !initialQuery.isEmpty()) {
    // Populate the search box but don't trigger the search
    queryTextView.setText(initialQuery);
  }
  queryTextView.setOnKeyListener(keyListener);

  queryButton = findViewById(R.id.query_button);
  queryButton.setOnClickListener(buttonListener);

  resultListView = (ListView) findViewById(R.id.result_list_view);
  LayoutInflater factory = LayoutInflater.from(this);
  headerView = (TextView) factory.inflate(R.layout.search_book_contents_header,
      resultListView, false);
  resultListView.addHeaderView(headerView);
}
 
Example #25
Source Project: MHViewer   Author: axlecho   File: MyTagsActivity.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
  CookieManager cookieManager = CookieManager.getInstance();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    cookieManager.flush();
    cookieManager.removeAllCookies(null);
    cookieManager.removeSessionCookies(null);
  } else {
    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(this);
    cookieSyncManager.startSync();
    cookieManager.removeAllCookie();
    cookieManager.removeSessionCookie();
    cookieSyncManager.stopSync();
  }

  // Copy cookies from okhttp cookie store to CookieManager
  url = EhUrl.getMyTagsUrl();
  EhCookieStore store = EhApplication.getEhCookieStore(this);
  for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
    cookieManager.setCookie(url, cookie.toString());
  }

  setContentView(R.layout.activity_my_tags);
  setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
  webView = findViewById(R.id.webview);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new MyTagsWebViewClient());
  webView.setWebChromeClient(new DialogWebChromeClient(this));
  webView.loadUrl(url);
  progress = findViewById(R.id.progress);
}
 
Example #26
Source Project: MHViewer   Author: axlecho   File: UConfigActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
  super.onDestroy();
  webView.destroy();

  // Put cookies back to okhttp cookie store
  CookieManager cookieManager = CookieManager.getInstance();
  String cookiesString = cookieManager.getCookie(url);

  if (cookiesString != null && !cookiesString.isEmpty()) {
    EhCookieStore store = EhApplication.getEhCookieStore(this);
    HttpUrl eUrl = HttpUrl.parse(EhUrl.HOST_E);
    HttpUrl exUrl = HttpUrl.parse(EhUrl.HOST_EX);

    // The cookies saved in the uconfig page should be shared between e and ex
    for (String header : cookiesString.split(";")) {
      Cookie eCookie = Cookie.parse(eUrl, header);
      if (eCookie != null) {
        store.addCookie(longLive(eCookie));
      }

      Cookie exCookie = Cookie.parse(exUrl, header);
      if (exCookie != null) {
        store.addCookie(longLive(exCookie));
      }
    }
  }
}
 
Example #27
Source Project: AndroidWallet   Author: Cocos-BCX   File: HtmlWebViewActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    CookieSyncManager.createInstance(this);  //Create a singleton CookieSyncManager within a context
    CookieManager cookieManager = CookieManager.getInstance(); // the singleton CookieManager instance
    cookieManager.removeAllCookie();// Removes all cookies.
    CookieSyncManager.getInstance().sync(); // forces sync manager to sync now
    binding.htmlWebView.setWebChromeClient(null);
    binding.htmlWebView.setWebViewClient(null);
    binding.htmlWebView.getSettings().setJavaScriptEnabled(false);
    binding.htmlWebView.destroy();
    super.onDestroy();
}
 
Example #28
Source Project: Android-SmartWebView   Author: mgks   File: MainActivity.java    License: MIT License 5 votes vote down vote up
public String get_cookies(String cookie){
	String value = "";
	CookieManager cookieManager = CookieManager.getInstance();
	String cookies = cookieManager.getCookie(ASWV_URL);
	String[] temp=cookies.split(";");
	for (String ar1 : temp ){
		if(ar1.contains(cookie)){
			String[] temp1=ar1.split("=");
			value = temp1[1];
			break;
		}
	}
	return value;
}
 
Example #29
Source Project: NGA-CLIENT-VER-OPEN-SOURCE   Author: ymback   File: LoginWebFragment.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void setCookies() {
        String cookieStr = CookieManager.getInstance().getCookie(mWebView.getUrl());
        if (!StringUtils.isEmpty(cookieStr)) {
            mLoginPresenter.parseCookie(cookieStr);
//            Toast.makeText(mActivity, "登陆成功", Toast.LENGTH_SHORT).show();
            if (mActivity != null) {
                mActivity.setResult(Activity.RESULT_OK);
            }
        }
    }
 
Example #30
Source Project: mobile-sdk-android   Author: appnexus   File: WebviewUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getCookie() {
    try {
        CookieManager cm = CookieManager.getInstance();
        if (cm == null) {
            Clog.i(Clog.httpRespLogTag, "Unable to find a CookieManager");
            return null;
        }
        return cm.getCookie(Settings.getBaseUrl());
    }catch (Exception e){
        // Catches PackageManager$NameNotFoundException for webview
        Clog.e(Clog.httpRespLogTag, "Unable to find a CookieManager - Exception: "+e.getMessage());
    }
    return null;
}