List of usage examples for android.webkit CookieManager getInstance
public static CookieManager getInstance()
From source file:com.btmura.android.reddit.app.LoginFragment.java
private void setupWebView() { // Clear reddit cookie to present a fresh login form. CookieManager.getInstance().setCookie(".reddit.com", "reddit_session="); WebSettings settings = webView.getSettings(); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setLoadWithOverviewMode(true); settings.setSupportZoom(true);/*w w w .j a va2 s .c o m*/ settings.setUseWideViewPort(true); // Don't save usernames entered into the login forms. settings.setSaveFormData(false); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (progressBar != null) { progressBar.setVisibility(View.VISIBLE); } } @Override public void onPageFinished(WebView view, String url) { if (progressBar != null) { progressBar.setVisibility(View.GONE); } } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // WebView will show an unrecognized scheme error unless we intercept // the OAuth callback URL and fire off an intent instead. return url != null && url.startsWith(Urls.OAUTH_REDIRECT_URL) && handleOAuthRedirectUrl(url); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (progressBar != null) { progressBar.setProgress(newProgress); } } }); }
From source file:com.msplearning.android.ext.FacebookWebOAuthActivity.java
@Override protected void onResume() { super.onResume(); // clear the Facebook session cookie CookieManager.getInstance().removeAllCookie(); }
From source file:com.sym.demozxing.zxing.book.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();//w ww .j a v a2 s .com if (intent == null || !Intents.SearchBookContents.ACTION.equals(intent.getAction())) { finish(); return; } isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN); if (LocaleManager.isBookSearchUrl(isbn)) { 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.isEmpty()) { // Populate the search box but don't trigger the search queryTextView.setText(initialQuery); } queryTextView.setOnKeyListener(keyListener); queryButton = 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:org.forgerock.openam.mobile.example.oauth2.activities.webview.AuthorizeWebClient.java
/** * Configures the client with the token needed to authenticate to the server * * @param resource The openam server information *//*from ww w .j a v a 2s . c o m*/ private void configureClient(OpenAMServerResource resource) { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); if (tokenId != null) { String cookieName = authNClient.getCookieNameWithDefault(AppConstants.DEFAULT_COOKIE_NAME); String domain = authNClient.getCookieDomainWithDefault(Uri.parse(resource.getOpenAmBase()).getHost()); String url = authNClient.getOpenAmServerResource().getWebLoginUrl(); insertCookie(cookieName, tokenId, domain, url); } }
From source file:com.opemind.cartspage.client.android.book.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 a2 s . c o m*/ if (intent == null || !intent.getAction().equals(Intents.SearchBookContents.ACTION)) { finish(); return; } isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN); if (LocaleManager.isBookSearchUrl(isbn)) { 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.isEmpty()) { // Populate the search box but don't trigger the search queryTextView.setText(initialQuery); } queryTextView.setOnKeyListener(keyListener); queryButton = 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.hua.nowid.activity.WebViewFragment.java
public void updateSecureCookie() { CookieSyncManager.createInstance(this.getActivity().getApplicationContext()); CookieManager cookieManager = CookieManager.getInstance(); String cookieString = "NOWSESSIONID=" + NowIDLoginStatus.getInstance().getSecureCookie(); cookieManager.removeAllCookie();// www . ja va2s . c om cookieManager.setCookie(".now.com", cookieString); Log.v("WebViewFragment", cookieString); CookieSyncManager.getInstance().sync(); }
From source file:net.evecom.androidecssp.base.BaseWebActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; temp = HttpUtil.getPageSize(this); setContentView(R.layout.message_post_web); // dialog = ProgressDialog.show(BaseWebActivity.this, null, // "..");// ww w . j a va 2s . co m // dialog.setCancelable(true); lineProgressBar = (ProgressBar) findViewById(R.id.webview_progress_id); imageView = (ImageView) findViewById(R.id.image_view_at_web); webView = (WebView) this.findViewById(R.id.wv_oauth_message); CookieSyncManager.createInstance(this); CookieSyncManager.getInstance().startSync(); CookieManager.getInstance().removeSessionCookie(); webView.setWebViewClient(new BaseWebViewClient((BaseWebActivity) instance)); webView.setWebChromeClient(new BaseChromeClient((BaseWebActivity) instance)); // webView.setDownloadListener(new MyWebViewDownLoadListener()); WebSettings webSettings = webView.getSettings(); webSettings.setSupportZoom(true); // WebViewJavaScript webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setBuiltInZoomControls(true);// support zoom webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); /** */ // // webSettings.setDatabaseEnabled(true); String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); // webSettings.setGeolocationEnabled(true); // webSettings.setGeolocationDatabasePath(dir); // webSettings.setDomStorageEnabled(true); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int mDensity = metrics.densityDpi; if (mDensity == 240) { webSettings.setDefaultZoom(ZoomDensity.FAR); } else if (mDensity == 160) { webSettings.setDefaultZoom(ZoomDensity.MEDIUM); } else if (mDensity == 120) { webSettings.setDefaultZoom(ZoomDensity.CLOSE); // }else if(mDensity == DisplayMetrics..DENSITY_XHIGH){ // webSettings.setDefaultZoom(ZoomDensity.FAR); } else if (mDensity == DisplayMetrics.DENSITY_HIGH) { webSettings.setDefaultZoom(ZoomDensity.FAR); } dialogPress = new AlertDialog.Builder(this).setTitle("").setMessage(":0/0") .setPositiveButton("", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); webView.addJavascriptInterface(new JsInterface(getApplicationContext()), "androidbase"); String url = HttpUtil.getPCURL() + "jfs/mobile/androidIndex/jqmobileTest"; // post // webView.postUrl(url, postData) postDatabyte[] // EncodingUtils.getBytes("&pwd=888", charset) webView.postUrl(url, EncodingUtils.getBytes("", "BASE64")); }
From source file:it.evilsocket.dsploit.plugins.mitm.hijacker.HijackerWebView.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); requestWindowFeature(Window.FEATURE_PROGRESS); setTitle(System.getCurrentTarget() + " > MITM > Session Hijacker"); setContentView(R.layout.plugin_mitm_hijacker_webview); getSupportActionBar().setDisplayHomeAsUpEnabled(true); setSupportProgressBarIndeterminateVisibility(false); mWebView = (WebView) findViewById(R.id.webView); mSettings = mWebView.getSettings();//from ww w. ja va 2 s .c om mSettings.setJavaScriptEnabled(true); mSettings.setBuiltInZoomControls(true); mSettings.setAppCacheEnabled(false); mSettings.setUserAgentString(DEFAULT_USER_AGENT); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { if (mWebView != null) getSupportActionBar().setSubtitle(mWebView.getUrl()); setSupportProgressBarIndeterminateVisibility(true); // Normalize our progress along the progress bar's scale int mmprogress = (Window.PROGRESS_END - Window.PROGRESS_START) / 100 * progress; setSupportProgress(mmprogress); if (progress == 100) setSupportProgressBarIndeterminateVisibility(false); } }); CookieSyncManager.createInstance(this); CookieManager.getInstance().removeAllCookie(); Session session = (Session) System.getCustomData(); if (session != null) { String domain = null, rawcookie = null; for (BasicClientCookie cookie : session.mCookies.values()) { domain = cookie.getDomain(); rawcookie = cookie.getName() + "=" + cookie.getValue() + "; domain=" + domain + "; path=/" + (session.mHTTPS ? ";secure" : ""); CookieManager.getInstance().setCookie(domain, rawcookie); } CookieSyncManager.getInstance().sync(); if (session.mUserAgent != null && session.mUserAgent.isEmpty() == false) mSettings.setUserAgentString(session.mUserAgent); mWebView.loadUrl((session.mHTTPS ? "https" : "http") + "://www." + domain); } }
From source file:net.ecfirm.ec.ec1.net.EcNet.java
protected void setCookie() throws Exception { Cookie cookie = null;/* w w w . j a v a 2 s.c o m*/ if ((EcNetHelper.cookies != null) && (EcNetHelper.cookies.size() > 0)) cookie = EcNetHelper.cookies.get(0); CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); if (cookie != null) { cookieManager.removeSessionCookie(); String cookieStr = cookie.getName() + "=" + cookie.getValue() + "; domain=" + cookie.getDomain(); cookieManager.setCookie(net.getProtocol() + "://" + net.getHost(), cookieStr); CookieSyncManager.getInstance().sync(); } }
From source file:com.bez4pieci.cookies.Cookies.java
public void setCookie(String action, JSONArray args, CallbackContext callbackContext) { Log.v(TAG, "Setting cookie"); if (args.length() == 0) { System.err.println("Exception: No Arguments passed"); } else {/*from w w w . ja v a2 s. co m*/ try { JSONObject options = args.getJSONObject(0); String protocol = DEFAULT_PROTOCOL; String host = null; int port = DEFAULT_PORT; String path = null; // Set the protocol if (options.has("protocol")) { protocol = options.getString("protocol"); } // Set the domain/host if (options.has("domain")) { host = options.getString("domain"); } else if (options.has("host")) { host = options.getString("host"); } // Set the port if (options.has("port")) { port = options.getInt("port"); } // Set the file/path if (options.has("file")) { path = options.getString("file"); } else if (options.has("path")) { path = options.getString("path"); } URL url = new URL(protocol, host, port, path); CookieManager.getInstance().setCookie(url.toString(), options.optString("value")); } catch (JSONException e) { Log.e(TAG, "Exception while setting cookie", e); } catch (MalformedURLException e) { Log.e(TAG, "Exception while setting cookie", e); } } }