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

The following examples show how to use android.webkit.CookieManager#removeAllCookies() . 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: WebViewSignInScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
public View onCreateView2(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    Context context = getContext2();
    AssertUtils.assertNotNull(context);

    EhUtils.signOut(context);

    // 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(context);
        cookieSyncManager.startSync();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncManager.stopSync();
    }

    mWebView = new WebView(context);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new LoginWebViewClient());
    mWebView.loadUrl(EhUrl.URL_SIGN_IN);
    return mWebView;
}
 
Example 2
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 3
Source File: UConfigActivity.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.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 4
Source File: BrowserActivity.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public void clearCookies() {
	// TODO Break out web storage deletion into its own option/action
	// TODO clear web storage for all sites that are visited in Incognito mode
	WebStorage storage = WebStorage.getInstance();
	storage.deleteAllData();
	CookieManager c = CookieManager.getInstance();
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		c.removeAllCookies(null);
	} else {
		CookieSyncManager.createInstance(this);
		c.removeAllCookie();
	}
}
 
Example 5
Source File: WebUtils.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
public static void clearCookies(@NonNull Context context) {
    CookieManager c = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        c.removeAllCookies(null);
    } else {
        //noinspection deprecation
        CookieSyncManager.createInstance(context);
        //noinspection deprecation
        c.removeAllCookie();
    }
}
 
Example 6
Source File: WebUtils.java    From JumpGo with Mozilla Public License 2.0 5 votes vote down vote up
public static void clearCookies(@NonNull Context context) {
    CookieManager c = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        c.removeAllCookies(null);
    } else {
        //noinspection deprecation
        CookieSyncManager.createInstance(context);
        //noinspection deprecation
        c.removeAllCookie();
    }
}
 
Example 7
Source File: WebViewSignInScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
public View onCreateView2(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    Context context = getContext2();
    AssertUtils.assertNotNull(context);

    EhUtils.signOut(context);

    // 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(context);
        cookieSyncManager.startSync();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncManager.stopSync();
    }

    mWebView = new WebView(context);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new LoginWebViewClient());
    mWebView.loadUrl(EhUrl.URL_SIGN_IN);
    return mWebView;
}
 
Example 8
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 9
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 10
Source File: CompatibilityImpl.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void clearCookies(CookieManager cookieManager) {
    cookieManager.removeAllCookies(null);
}