Java Code Examples for android.webkit.CookieManager#getInstance()
The following examples show how to use
android.webkit.CookieManager#getInstance() .
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: Util.java From CoolApk-Console with GNU General Public License v3.0 | 6 votes |
/** * @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 2
Source File: a.java From letv with Apache License 2.0 | 6 votes |
public static void a(Context context, String str, String str2, String str3, String str4) { if (!TextUtils.isEmpty(str)) { CookieSyncManager.createInstance(context); CookieManager instance = CookieManager.getInstance(); instance.setAcceptCookie(true); String str5 = null; if (Uri.parse(str).getHost().toLowerCase().endsWith(".qq.com")) { str5 = ".qq.com"; } instance.setCookie(str, b("logintype", "MOBILEQ", str5)); instance.setCookie(str, b("qopenid", str2, str5)); instance.setCookie(str, b("qaccesstoken", str3, str5)); instance.setCookie(str, b("openappid", str4, str5)); CookieSyncManager.getInstance().sync(); } }
Example 3
Source File: EvernoteSession.java From EverMemo with MIT License | 6 votes |
/** * 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 4
Source File: PreferenceActivity.java From talk-android with MIT License | 6 votes |
public void signOut() { RealmConfig.deleteRealm(); MainApp.PREF_UTIL.clear(); CookieManager cookieManager = CookieManager.getInstance(); try { cookieManager.removeAllCookie(); } catch (Exception e) { } NotificationUtil.stopPush(MainApp.CONTEXT); Intent intent = new Intent(this, Oauth2Activity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); BizLogic.cancelSync(); startActivity(intent); // disconnect message service Intent closeMsgIntent = new Intent(this, MessageService.class); closeMsgIntent.setAction(MessageService.ACTION_CLOSE); startService(closeMsgIntent); }
Example 5
Source File: WebViewSignInScene.java From EhViewer with Apache License 2.0 | 5 votes |
@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 6
Source File: AuthorizeActivity.java From YiBo with Apache License 2.0 | 5 votes |
@Override public void finish() { // 清空授权后留下的Cookie CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); super.finish(); }
Example 7
Source File: BrowserActivity.java From browser with GNU General Public License v2.0 | 5 votes |
@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 8
Source File: SystemCookieManager.java From a2cardboard with Apache License 2.0 | 5 votes |
public SystemCookieManager(WebView webview) { webView = webview; cookieManager = CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.setAcceptThirdPartyCookies(webView, true); } }
Example 9
Source File: SystemCookieManager.java From keemob with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public SystemCookieManager(WebView webview) { webView = webview; cookieManager = CookieManager.getInstance(); //REALLY? Nobody has seen this UNTIL NOW? cookieManager.setAcceptFileSchemeCookies(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.setAcceptThirdPartyCookies(webView, true); } }
Example 10
Source File: SystemCookieManager.java From cordova-plugin-intent with MIT License | 5 votes |
public SystemCookieManager(WebView webview) { webView = webview; cookieManager = CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.setAcceptThirdPartyCookies(webView, true); } }
Example 11
Source File: WebUtils.java From JumpGo with Mozilla Public License 2.0 | 5 votes |
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 12
Source File: MainActivity.java From Android-SmartWebView with MIT License | 5 votes |
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 13
Source File: SystemCookieManager.java From BigDataPlatform with GNU General Public License v3.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public SystemCookieManager(WebView webview) { webView = webview; cookieManager = CookieManager.getInstance(); //REALLY? Nobody has seen this UNTIL NOW? cookieManager.setAcceptFileSchemeCookies(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.setAcceptThirdPartyCookies(webView, true); } }
Example 14
Source File: SamlWebViewDialog.java From Cirrus_depricated with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("deprecation") @SuppressLint("SetJavaScriptEnabled") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log_OC.v(TAG, "onCreateView, savedInsanceState is " + savedInstanceState); // Inflate layout of the dialog RelativeLayout ssoRootView = (RelativeLayout) inflater.inflate(R.layout.sso_dialog, container, false); // null parent view because it will go in the dialog layout if (mSsoWebView == null) { // initialize the WebView mSsoWebView = new SsoWebView(getActivity().getApplicationContext()); mSsoWebView.setFocusable(true); mSsoWebView.setFocusableInTouchMode(true); mSsoWebView.setClickable(true); WebSettings webSettings = mSsoWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(false); webSettings.setLoadWithOverviewMode(false); webSettings.setSavePassword(false); webSettings.setUserAgentString(MainApp.getUserAgent()); webSettings.setSaveFormData(false); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeAllCookie(); mSsoWebView.loadUrl(mInitialUrl); } mWebViewClient.setTargetUrl(mTargetUrl); mSsoWebView.setWebViewClient(mWebViewClient); // add the webview into the layout RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT ); ssoRootView.addView(mSsoWebView, layoutParams); ssoRootView.requestLayout(); return ssoRootView; }
Example 15
Source File: OAuthActivity.java From iBeebo with GNU General Public License v3.0 | 4 votes |
@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(); }
Example 16
Source File: DefaultSonicRuntimeImpl.java From AgentWeb with Apache License 2.0 | 4 votes |
@Override public String getCookie(String url) { CookieManager cookieManager = CookieManager.getInstance(); return cookieManager.getCookie(url); }
Example 17
Source File: WebViewActivity.java From iBeebo with GNU General Public License v3.0 | 4 votes |
@Override public void onComplete(Bundle values) { // TODO Auto-generated method stub CookieManager cookieManager = CookieManager.getInstance(); String cookie = cookieManager.getCookie(SeniorUrl.SeniorUrl_SeniorLogin); // setWeiboCookie(CookieStr); String uid = ""; String uname = ""; AccountDatabaseManager manager = new AccountDatabaseManager(getApplicationContext()); if (true) { String[] cookies = cookie.split("; "); for (String string : cookies) { // Log.d("Weibo-Cookie", "" + Uri.decode(Uri.decode(string))); String oneLine = Uri.decode(Uri.decode(string)); String uidtmp = PatternUtils.macthUID(oneLine); if (!TextUtils.isEmpty(uidtmp)) { uid = uidtmp; } uname = PatternUtils.macthUname(oneLine); // Log.d("Weibo-Cookie", "" + uid); // Log.d("Weibo-Cookie", "" + uname); // Log.d("Weibo-Cookie", "in db : uid = " + mAccountBean.getUid()); if (!TextUtils.isEmpty(uname)) { manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.USER_NAME, uname); } } } Log.d("Weibo-Cookie", "after for : " + uid); if (uid.equals(mAccountBean.getUid())) { manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.COOKIE, cookie); cookieManager.removeSessionCookie(); finish(); } else if (!TextUtils.isEmpty(uid)) { Toast.makeText(getApplicationContext(), "请登录昵称是[" + mAccountBean.getUsernick() + "]的微博!", Toast.LENGTH_LONG) .show(); mWebView.loadUrl(SeniorUrl.SeniorUrl_SeniorLogin); } }
Example 18
Source File: LetvBaseWebViewActivity.java From letv with Apache License 2.0 | 4 votes |
private void setCookie() { CookieManager cookieManager = CookieManager.getInstance(); LetvUtils.setCookies(this, this.baseUrl); LogInfo.log("wlx", "setCookies之后 baseCookie: " + cookieManager.getCookie(this.baseUrl)); }
Example 19
Source File: JSWebViewActivity.java From iBeebo with GNU General Public License v3.0 | 4 votes |
@Override public void onComplete(Bundle values) { // TODO Auto-generated method stub CookieManager cookieManager = CookieManager.getInstance(); String cookie = cookieManager.getCookie(url); // setWeiboCookie(CookieStr); String uid = ""; String uname = ""; AccountDatabaseManager manager = new AccountDatabaseManager(getApplicationContext()); if (true) { String[] cookies = cookie.split("; "); for (String string : cookies) { // Log.d("Weibo-Cookie", "" + Uri.decode(Uri.decode(string))); String oneLine = Uri.decode(Uri.decode(string)); String uidtmp = PatternUtils.macthUID(oneLine); if (!TextUtils.isEmpty(uidtmp)) { uid = uidtmp; } uname = PatternUtils.macthUname(oneLine); // Log.d("Weibo-Cookie", "" + uid); // Log.d("Weibo-Cookie", "" + uname); // Log.d("Weibo-Cookie", "in db : uid = " + mAccountBean.getUid()); if (!TextUtils.isEmpty(uname)) { manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.USER_NAME, uname); } } } Log.d("Weibo-Cookie", "after for : " + uid); if (uid.equals(mAccountBean.getUid())) { manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.COOKIE, cookie); BeeboApplication.getInstance().updateAccountBean(); finish(); } else if (!TextUtils.isEmpty(uid)) { Toast.makeText(getApplicationContext(), "请登录昵称是[" + mAccountBean.getUsernick() + "]的微博!", Toast.LENGTH_LONG) .show(); mWebView.loadUrl(url); } }
Example 20
Source File: VideoWebView.java From mobile-sdk-android with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") @SuppressLint("SetJavaScriptEnabled") protected void setupSettings() { Settings.getSettings().ua = this.getSettings().getUserAgentString(); this.getSettings().setJavaScriptEnabled(true); this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); this.getSettings().setBuiltInZoomControls(false); this.getSettings().setLightTouchEnabled(false); this.getSettings().setLoadsImagesAutomatically(true); this.getSettings().setSupportZoom(false); this.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); this.getSettings().setUseWideViewPort(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { this.getSettings().setMediaPlaybackRequiresUserGesture(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } this.getSettings().setAllowFileAccess(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { this.getSettings().setAllowContentAccess(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { this.getSettings().setAllowFileAccessFromFileURLs(false); this.getSettings().setAllowUniversalAccessFromFileURLs(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CookieManager cm = CookieManager.getInstance(); if (cm != null) { cm.setAcceptThirdPartyCookies(this, true); } else { Clog.d(Clog.videoLogTag, "Failed to set Webview to accept 3rd party cookie"); } } setHorizontalScrollbarOverlay(false); setHorizontalScrollBarEnabled(false); setVerticalScrollbarOverlay(false); setVerticalScrollBarEnabled(false); setBackgroundColor(Color.TRANSPARENT); setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); }