下面列出了android.webkit.CookieManager#removeAllCookies ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
@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);
}
@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();
}
@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();
}
}
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();
}
}
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();
}
}
@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;
}
@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);
}
@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();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void clearCookies(CookieManager cookieManager) {
cookieManager.removeAllCookies(null);
}