List of usage examples for android.webkit CookieManager getInstance
public static CookieManager getInstance()
From source file:org.forgerock.openam.mobile.example.oauth2.activities.webview.AuthorizeWebClient.java
/** * Used to append our authentication cookie to the authorization request * * @param name name of the cookie/* w ww .ja va2 s .co m*/ * @param value value of the cookie * @param domain domain in which the cookie applies * @param url url to register the cookie against in the cookie manager */ public void insertCookie(String name, String value, String domain, String url) { StringBuilder cookie = new StringBuilder(name); cookie.append("=").append(value); cookie.append("; domain=").append(domain); cookie.append("; path=/"); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.setCookie(url, cookie.toString()); }
From source file:com.citrus.mobile.User.java
public final static boolean logoutUser(Context context) { CookieSyncManager.createInstance(context); String setCookie = CookieManager.getInstance().getCookie(Config.getBaseURL()); CookieManager.getInstance().setCookie(Config.getBaseURL(), Constants.CITRUS_PREPAID_COOKIE);//remove App Cookie new PersistentConfig(context).clearToken(); //clear stored cookies OauthToken token = new OauthToken(context, ""); return token.clearToken(); //clear stored oauth token }
From source file:org.projecthdata.hhub.ui.HDataWebOauthActivity.java
@Override public void onCreate(Bundle savedInstanceState) { getWindow().requestFeature(Window.FEATURE_PROGRESS); getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); super.onCreate(savedInstanceState); webView = new WebView(this); setContentView(webView);//from w w w . j ava 2 s . c o m this.ehrUrl = getIntent().getStringExtra(EXTRA_EHR_URL); activity = this; this.connectionRepository = getApplicationContext().getConnectionRepository(); this.hDataConnectionFactory = getApplicationContext().getHDataConnectionFactory(ehrUrl); webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { activity.setTitle("Loading..."); activity.setProgress(progress * 100); if (progress == 100) { activity.setTitle(R.string.app_name); } } }); webView.setWebViewClient(new MyWebViewClient()); // clear out any previously used credentials webView.clearCache(true); webView.clearFormData(); webView.clearHistory(); webView.getSettings().setSavePassword(false); webView.getSettings().setSaveFormData(false); CookieSyncManager.createInstance(this); CookieManager.getInstance().removeAllCookie(); }
From source file:com.tdispatch.passenger.fragment.OAuthFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override//from w w w . ja v a 2 s. c om protected void onPostCreateView() { View v = mFragmentView.findViewById(R.id.button_cancel); v.setOnClickListener(mOnClickListener); ProgressBar pb = (ProgressBar) mFragmentView.findViewById(R.id.progressbar); pb.setVisibility(View.GONE); mWebView = (WebView) mFragmentView.findViewById(R.id.webview); if (mWebView != null) { mWebView.setWebViewClient(new MyWebViewClient()); mWebView.setWebChromeClient(new MyWebchromeClient()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { mWebView.setOnTouchListener(mOnTouchListener); } WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); webSettings.setAppCacheEnabled(false); webSettings.setSavePassword(false); webSettings.setSaveFormData(false); CookieSyncManager.createInstance(mContext); CookieManager cm = CookieManager.getInstance(); cm.setAcceptCookie(true); cm.removeAllCookie(); try { ApiRequest req = new ApiRequest(Const.Api.OauthAuthUrl); req.addGetParam("key", Const.getApiKey()); req.addGetParam("scope", ""); req.addGetParam("response_type", "code"); req.addGetParam("client_id", Const.getOAuthClientId()); req.addGetParam("redirect_uri", mOAuthRedirectUrl); req.buildRequest(); String url = req.getUrl(); mWebView.loadUrl(url); } catch (Exception e) { WebnetLog.e("Failed to load oauth launch page..."); } } else { WebnetLog.e("Failed to init WebView. Aborting"); mHostActivity.oAuthCancelled(); } }
From source file:com.directsiding.android.WebActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_web); // Le ponemos la font Signika al titulo del Action Bar SpannableString s = new SpannableString(getString(R.string.app_name)); s.setSpan(new TypefaceSpan(this, LoginActivity.PATH_SIGNIKA_FONT), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Agregamos lo necesario al Action Bar ActionBar actionBar = getSupportActionBar(); actionBar.setTitle(s);//from ww w. j a v a 2 s . com actionBar.setDisplayShowHomeEnabled(true); actionBar.setHomeButtonEnabled(true); // Obtenemos la url a la que el usuario va a ingresar String url = getIntent().getExtras().getString(LoginActivity.EXTRA_URL); // Obtenemos la cookie y la agregamos al webview Cookie sessionCookie = LoginOpActivity.cookie; CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); if (sessionCookie != null) { //cookieManager.removeSessionCookie(); String cookieString = sessionCookie.getName() + "=" + sessionCookie.getValue() + "; domain=" + sessionCookie.getDomain(); cookieManager.setCookie(LoginActivity.POST_URL, cookieString); CookieSyncManager.getInstance().sync(); } mProgressBar = (ProgressBar) findViewById(R.id.progressBar_webView); webView = (WebView) findViewById(R.id.webView_ing); webViewConfig(); webView.loadUrl(url); //webView.loadUrl("http://www.google.com"); // guardamos el tiempo en el que se creo la actividad lastTimeStamp = SystemClock.elapsedRealtime(); }
From source file:com.easy.facebook.android.facebook.FBLoginManager.java
public void logout(Facebook facebook) throws EasyFacebookError { SharedPreferences preferences = this.getActivity().getSharedPreferences(appID, 0); android.content.SharedPreferences.Editor editor = preferences.edit(); editor.putString("accessToken", ""); editor.putString("uid", ""); editor.clear();//from ww w .ja v a 2 s. c om editor.commit(); CookieSyncManager.createInstance(activity); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("method", "auth.expireSession"); String jsonResponse = ""; try { jsonResponse = Util.openUrl("https://api.facebook.com/restserver.php", "GET", params); if (!jsonResponse.equals("true")) { JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error_msg")) { throw new EasyFacebookError(jsonResponse); } } } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } ((LoginListener) activity).logoutSuccess(); }
From source file:com.liato.bankdroid.WebViewActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview);//from ww w. j a v a 2 s . c o m this.addTitleButton(R.drawable.title_icon_back, "back", this); this.addTitleButton(R.drawable.title_icon_forward, "forward", this); this.addTitleButton(R.drawable.title_icon_refresh, "refresh", this); this.setTitleButtonEnabled("forward", false); this.setTitleButtonEnabled("back", false); this.setTitleButtonEnabled("refresh", false); final CookieSyncManager csm = CookieSyncManager.createInstance(this); mWebView = (WebView) findViewById(R.id.wvBank); mWebView.setBackgroundColor(0); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.getSettings().setUserAgentString(Urllib.DEFAULT_USER_AGENT); mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { activity.setProgressBar(progress); if (progress == 100) { Handler handler = new Handler(); Runnable runnable = new Runnable() { public void run() { activity.hideProgressBar(); } }; // Let the progress bar hit 100% before we hide it. handler.postDelayed(runnable, 100); } else if (mFirstPageLoaded) { activity.showProgressBar(); } } }); mWebView.setWebViewClient(new BankWebViewClient()); String preloader = "Error..."; try { preloader = IOUtils.toString(getResources().openRawResource(R.raw.loading)); preloader = String.format(preloader, "", // Javascript function "" // HTML ); } catch (NotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } mWebView.loadDataWithBaseURL("what://is/this/i/dont/even", preloader, "text/html", "utf-8", null); Bundle extras = getIntent().getExtras(); final long bankId = extras.getLong("bankid", -1); //final long bankId = -1; if (bankId >= 0) { Runnable generateLoginPage = new Runnable() { public void run() { Bank bank = BankFactory.bankFromDb(bankId, WebViewActivity.this, false); SessionPackage loginPackage = bank.getSessionPackage(WebViewActivity.this); CookieStore cookieStore = loginPackage.getCookiestore(); if ((cookieStore != null) && !cookieStore.getCookies().isEmpty()) { CookieManager cookieManager = CookieManager.getInstance(); String cookieString; for (Cookie cookie : cookieStore.getCookies()) { cookieString = String.format("%s=%s;%spath=%s; domain=%s;", cookie.getName(), cookie.getValue(), cookie.getExpiryDate() == null ? "" : "expires=" + cookie.getExpiryDate() + "; ", cookie.getPath() == null ? "/" : cookie.getPath(), cookie.getDomain()); cookieManager.setCookie(cookie.getDomain(), cookieString); } csm.sync(); } mWebView.loadDataWithBaseURL("what://is/this/i/dont/even", loginPackage.getHtml(), "text/html", "utf-8", null); } }; new Thread(generateLoginPage).start(); } }
From source file:com.hhunj.hhudata.SearchBookContentsActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // Make sure that expired cookies are removed on launch. CookieSyncManager.createInstance(this); CookieManager.getInstance().removeExpiredCookie(); Intent intent = getIntent();//from w w w . j a v a 2 s. co m if (intent == null || (!intent.getAction().equals(Intents.SearchBookContents.ACTION))) { finish(); return; } //pageid,pagenumber //ISBN ---stationid, isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN);//stationid if (isbn.startsWith("http://google.com/books?id=")) { setTitle(getString(R.string.sbc_name)); } else { setTitle(getString(R.string.sbc_name) + ": ISBN " + isbn); } setContentView(R.layout.search_book_contents); queryTextView = (EditText) findViewById(R.id.query_text_view); String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY); if (initialQuery != null && initialQuery.length() > 0) { // Populate the search box but don't trigger the search queryTextView.setText(initialQuery); } queryTextView.setOnKeyListener(keyListener); queryButton = (Button) findViewById(R.id.query_button); queryButton.setOnClickListener(buttonListener); resultListView = (ListView) findViewById(R.id.result_list_view); LayoutInflater factory = LayoutInflater.from(this); headerView = (TextView) factory.inflate(R.layout.search_book_contents_header, resultListView, false); resultListView.addHeaderView(headerView); }
From source file:com.nguyenmp.gauchodroid.login.LoginFragment.java
public static void setCookies(Context context, CookieStore cookies) { PersistentCookieStore store = new PersistentCookieStore(context); store.clear();/*ww w . j av a2s. c om*/ CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.setAcceptCookie(true); if (cookies != null) { for (Cookie cookie : cookies.getCookies()) { store.addCookie(cookie); cookieManager.setCookie(cookie.getDomain(), cookie.getName() + "=" + cookie.getValue()); } } CookieSyncManager.getInstance().sync(); }