每当登录cookie过期时,我必须检查加载URL是否以某个字符串结尾,然后我必须用另一个URL重定向它。我怎么能这样做?
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith("admin/login")) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("cookies", null).apply();
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(MainActivity.this);
cookieSyncMngr.startSync();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncMngr.stopSync();
cookieSyncMngr.sync();
}
view.clearHistory();
view.clearCache(true);
view.loadUrl(URL_BASIC);
} return true;
}
在这种情况下,通过 admin / login 网址重复拨打电话。它不会加载我提供的URL。