Java Code Examples for android.webkit.CookieManager#removeAllCookie()

The following examples show how to use android.webkit.CookieManager#removeAllCookie() . 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: TwitterDialog.java    From NewAndroidTwitter with Apache License 2.0 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView() {
   	CookieSyncManager.createInstance(getContext()); 
       CookieManager cookieManager = CookieManager.getInstance();
       cookieManager.removeAllCookie();
       
       mWebView = new WebView(getContext());
       
       mWebView.setVerticalScrollBarEnabled(false);
       mWebView.setHorizontalScrollBarEnabled(false);
       mWebView.setWebViewClient(new TwitterWebViewClient());
       mWebView.getSettings().setJavaScriptEnabled(true);
       mWebView.loadUrl(mUrl);
       mWebView.setLayoutParams(FILL);
       
       mContent.addView(mWebView);
   }
 
Example 2
Source File: InstagramPhotoPicker.java    From InstagramPhotoPicker-Android with MIT License 6 votes vote down vote up
static void logout(Context context) {
    Context applicationContext = context.getApplicationContext();
    SharedPreferences preferences = applicationContext.getSharedPreferences(PREFERENCE_FILE, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.remove(PREFERENCE_ACCESS_TOKEN);
    editor.remove(PREFERENCE_CLIENT_ID);
    editor.remove(PREFERENCE_REDIRECT_URI);
    editor.commit();
    cachedAccessToken = null;
    cachedClientId = null;
    cachedRedirectUri = null;

    CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    new WebView(context).clearCache(true);
}
 
Example 3
Source File: Cookies.java    From DelegateAdapter with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
    public static void clearCookies(Context context) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            //Log.d(C.TAG, "Using clearCookies code for API >=" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().flush();
        } else {
//            Log.d(C.TAG, "Using clearCookies code for API <" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));
            CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context);
            cookieSyncMngr.startSync();
            CookieManager cookieManager=CookieManager.getInstance();
            cookieManager.removeAllCookie();
            cookieManager.removeSessionCookie();
            cookieSyncMngr.stopSync();
            cookieSyncMngr.sync();
        }
    }
 
Example 4
Source File: EvernoteSession.java    From EverMemo with MIT License 6 votes vote down vote up
/**
 * Clear all stored authentication information.
 */
public void logOut(Context ctx) throws InvalidAuthenticationException {
  if(!isLoggedIn()) {
    throw new InvalidAuthenticationException("Must not call when already logged out");
  }
  synchronized (this) {
    mAuthenticationResult.clear(SessionPreferences.getPreferences(ctx));
    mAuthenticationResult = null;
  }

  // TODO The cookie jar is application scope, so we should only be removing
  // evernote.com cookies.
  CookieSyncManager.createInstance(ctx);
  CookieManager cookieManager = CookieManager.getInstance();
  cookieManager.removeAllCookie();
}
 
Example 5
Source File: Util.java    From CoolApk-Console with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @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();
    }
}
 
Example 6
Source File: InstagramDialog.java    From social-login-helper-Deprecated- with 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 7
Source File: WebViewActivity.java    From pre-dem-android with 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 8
Source File: InsLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 6 votes vote down vote up
@Override
public void recycle() {

    //清空所有Cookie
    CookieSyncManager.createInstance(mActivity);  //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

    mWebView.setWebChromeClient(null);
    mWebView.setWebViewClient(null);
    mWebView.getSettings().setJavaScriptEnabled(false);
    mWebView.clearCache(true);

    webParentView.removeAllViews();
    mWebView = null;
    mClientSecret = null;
    mClientId = null;
    super.recycle();
}
 
Example 9
Source File: VKSdk.java    From cordova-social-vk with Apache License 2.0 6 votes vote down vote up
/**
 * Wipes out information about the access token and clears cookies for internal browse
 */
@SuppressLint("NewApi")
public static void logout() {
    Context context = VKUIHelper.getApplicationContext();
    if (Build.VERSION.SDK_INT < 21) {
        CookieSyncManager.createInstance(context);
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
    } else {
        CookieManager.getInstance().removeAllCookies(null);
    }

    VKAccessToken.replaceToken(VKUIHelper.getApplicationContext(), null);

    updateLoginState(context);
}
 
Example 10
Source File: InstagramSession.java    From AndroidInstagram with Apache License 2.0 6 votes vote down vote up
/**
 * Reset user data
 */
public void reset() {
	Editor editor = mSharedPref.edit();
	
	editor.putString(ACCESS_TOKEN, 	"");
	editor.putString(USERID, 		"");
	editor.putString(USERNAME, 		"");
	editor.putString(FULLNAME, 		"");
	editor.putString(PROFILPIC, 	"");
	
	editor.commit();
	
	CookieSyncManager.createInstance(mContext);
	
	CookieManager cookieManager = CookieManager.getInstance();
	cookieManager.removeAllCookie();
}
 
Example 11
Source File: AuthorizeActivity.java    From YiBo with Apache License 2.0 5 votes vote down vote up
@Override
public void finish() {
	// 清空授权后留下的Cookie
	CookieManager cookieManager = CookieManager.getInstance();
	cookieManager.removeAllCookie();
	super.finish();
}
 
Example 12
Source File: StravaActivity.java    From android-oauth-client with Apache License 2.0 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 13
Source File: LogonManager.java    From letv with Apache License 2.0 5 votes vote down vote up
public void deleteCookie() {
    CookieSyncManager.createInstance(this.context).sync();
    CookieManager instance = CookieManager.getInstance();
    instance.setAcceptCookie(true);
    instance.removeAllCookie();
    LemallPlatform.getInstance().setCookieLinkdata("");
    System.gc();
}
 
Example 14
Source File: MyTagsActivity.java    From EhViewer with 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 15
Source File: UConfigActivity.java    From EhViewer with 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.getUConfigUrl();
  EhCookieStore store = EhApplication.getEhCookieStore(this);
  for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
    cookieManager.setCookie(url, cookie.toString());
  }

  setContentView(R.layout.activity_u_config);
  setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
  webView = (WebView) findViewById(R.id.webview);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new UConfigWebViewClient());
  webView.setWebChromeClient(new DialogWebChromeClient(this));
  webView.loadUrl(url);
  progress = (ProgressView) findViewById(R.id.progress);

  Snackbar.make(webView, R.string.apply_tip, Snackbar.LENGTH_LONG).show();
}
 
Example 16
Source File: MyTagsActivity.java    From MHViewer with 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 17
Source File: Util.java    From Klyph with MIT License 5 votes vote down vote up
public static void clearCookies(Context context) {
    // Edge case: an illegal state exception is thrown if an instance of
    // CookieSyncManager has not be created.  CookieSyncManager is normally
    // created by a WebKit view, but this might happen if you start the
    // app, restore saved state, and click logout before running a UI
    // dialog in a WebView -- in which case the app crashes
    @SuppressWarnings("unused")
    CookieSyncManager cookieSyncMngr =
        CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
}
 
Example 18
Source File: QunarWebActvity.java    From imsdk-android with MIT License 4 votes vote down vote up
public void synCookie() {

        //下面的变量都是暂时处理 日后逻辑清晰重新构成
        Boolean isHistory = mUrl.contains("main_controller");
        CookieSyncManager.createInstance(this);
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        if (isHistory) {
            cookieManager.removeAllCookie();
        }
        if (from != null && from.equals(Constants.BundleValue.UC_LOGIN)) {
            cookieManager.removeAllCookie();
        }
        if (!TextUtils.isEmpty(mUrl) && mUrl.contains(DOMAIN)) {
            String qvtStr = CurrentPreference.getInstance().getQvt();
            boolean qvt = false;
            if (!TextUtils.isEmpty(qvtStr) && !isHistory) {
                QVTResponseResult qvtResponseResult = JsonUtils.getGson().fromJson(qvtStr, QVTResponseResult.class);
                if (qvtResponseResult.ret) {
                    cookieManager.setCookie(DOMAIN, "_v=" + qvtResponseResult.data.vcookie + ";");
                    cookieManager.setCookie(DOMAIN, "_t=" + qvtResponseResult.data.tcookie + ";");
                    cookieManager.setCookie(DOMAIN, "_q=" + qvtResponseResult.data.qcookie + ";");
                    cookieManager.setCookie(DOMAIN, "q_d=" + QtalkNavicationService.getInstance().getXmppdomain() + ";");
                    qvt = true;
                }
            }
//            if (!isHistory) {
//                if (!qvt) {
//                    cookieManager.setCookie(DOMAIN, "_v=;");
//                    cookieManager.setCookie(DOMAIN, "_t=;");
//                    cookieManager.setCookie(DOMAIN, "_q=;");
//                    cookieManager.setCookie(DOMAIN, "q_d=;");
//                }
//            }
        }

        if (mUrl.contains("/package/plts/dashboard")) {
            cookieManager.setCookie(DOMAIN, "q_u=" + CurrentPreference.getInstance().getUserid() + ";");
            cookieManager.setCookie(DOMAIN, "q_nm=" + CurrentPreference.getInstance().getUserid() + ";");
            cookieManager.setCookie(DOMAIN, "q_d=" + QtalkNavicationService.getInstance().getXmppdomain() + ";");
        }

        if(isVideoAudioCall){
            cookieManager.setCookie(DOMAIN, "_caller=" + QtalkStringUtils.parseId(videoCaller) + ";");
            cookieManager.setCookie(DOMAIN, "_callee=" + QtalkStringUtils.parseId(videoCallee) + ";");
            cookieManager.setCookie(DOMAIN, "_calltime=" + System.currentTimeMillis() + ";");
            cookieManager.setCookie(DOMAIN, "u=" + CurrentPreference.getInstance().getUserid() + ";");
        }else {
            cookieManager.setCookie(DOMAIN, "_caller=;");
            cookieManager.setCookie(DOMAIN, "_callee=;");
            cookieManager.setCookie(DOMAIN, "_calltime=;");
            cookieManager.setCookie(DOMAIN, "u=;");
        }


        //默认种qckey
        cookieManager.setCookie(DOMAIN, "q_ckey=" + Protocol.getCKEY() + ";");

        if (QtalkSDK.getInstance().isLoginStatus()) {
            cookieManager.setCookie(DOMAIN, "_u=" + CurrentPreference.getInstance().getUserid() + ";");
            cookieManager.setCookie(DOMAIN, "q_u=" + CurrentPreference.getInstance().getUserid() + ";");
            cookieManager.setCookie(DOMAIN, "_k=" + CurrentPreference.getInstance().getVerifyKey() + ";");
            cookieManager.setCookie(DOMAIN, "q_d=" + QtalkNavicationService.getInstance().getXmppdomain() + ";");
        } else {
            cookieManager.setCookie(DOMAIN, "_u=;");
            cookieManager.setCookie(DOMAIN, "_k=;");
            cookieManager.setCookie(DOMAIN, "q_d=;");
        }

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            cookieManager.flush();
        } else {
            CookieSyncManager.getInstance().sync();
        }

        Logger.i("QunarWebActvity getCookie:"+ cookieManager.getCookie(DOMAIN));
    }
 
Example 19
Source File: UserStorage.java    From TLint with Apache License 2.0 4 votes vote down vote up
private void removeCookie() {
    CookieSyncManager.createInstance(mContext);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    CookieSyncManager.getInstance().sync();
}
 
Example 20
Source File: OAuthActivity.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.oauth_activity_layout);

    this.mIsAuthPro = getIntent().getBooleanExtra(Ext.KEY_IS_HACK, false);
    this.mAccountBean = getIntent().getParcelableExtra(Ext.KEY_ACCOUNT);

    Toolbar mToolbar = ViewUtility.findViewById(this, R.id.oauthToolbar);

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbar.setNavigationOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });

    getSupportActionBar().setTitle(mIsAuthPro ? R.string.oauth_senior_title : R.string.oauth_normal_title);

    mWebView = (WebView) findViewById(R.id.webView);
    mInjectJS = new InjectJS(mWebView);

    mWebView.setWebViewClient(new WeiboWebViewClient());

    mCircleProgressBar = (CircleProgressBar) findViewById(R.id.oauthProgress);

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSaveFormData(true);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    refresh();
}