List of usage examples for android.webkit CookieSyncManager getInstance
public static CookieSyncManager getInstance()
From source file:it.evilsocket.dsploit.plugins.mitm.hijacker.HijackerWebView.java
@Override protected void onResume() { super.onResume(); CookieSyncManager.getInstance().startSync(); }
From source file:it.evilsocket.dsploit.plugins.mitm.hijacker.HijackerWebView.java
@Override protected void onPause() { super.onPause(); CookieSyncManager.getInstance().stopSync(); }
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 w w w. j a v a2 s . co m 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.nguyenmp.gauchodroid.login.LoginFragment.java
public static void setCookies(Context context, CookieStore cookies) { PersistentCookieStore store = new PersistentCookieStore(context); store.clear();//w w w . ja va 2 s. co m 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(); }
From source file:com.andrewshu.android.reddit.reddits.PickSubredditActivity.java
@Override public void onResume() { super.onResume(); CookieSyncManager.getInstance().startSync(); }
From source file:com.andrewshu.android.reddit.reddits.PickSubredditActivity.java
@Override public void onPause() { super.onPause(); CookieSyncManager.getInstance().stopSync(); }
From source file:com.microsoft.aad.adal.AuthenticationActivity.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from w w w . j a v a2 s. c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView( this.getResources().getIdentifier("activity_authentication", "layout", this.getPackageName())); CookieSyncManager.createInstance(getApplicationContext()); CookieSyncManager.getInstance().sync(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); // Get the message from the intent mAuthRequest = getAuthenticationRequestFromIntent(getIntent()); if (mAuthRequest == null) { Log.d(TAG, "Request item is null, so it returns to caller"); Intent resultIntent = new Intent(); resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_CODE, AuthenticationConstants.Browser.WEBVIEW_INVALID_REQUEST); resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_MESSAGE, "Intent does not have request details"); returnToCaller(AuthenticationConstants.UIResponse.BROWSER_CODE_ERROR, resultIntent); return; } if (mAuthRequest.getAuthority() == null || mAuthRequest.getAuthority().isEmpty()) { returnError(ADALError.ARGUMENT_EXCEPTION, AuthenticationConstants.Broker.ACCOUNT_AUTHORITY); return; } if (mAuthRequest.getResource() == null || mAuthRequest.getResource().isEmpty()) { returnError(ADALError.ARGUMENT_EXCEPTION, AuthenticationConstants.Broker.ACCOUNT_RESOURCE); return; } if (mAuthRequest.getClientId() == null || mAuthRequest.getClientId().isEmpty()) { returnError(ADALError.ARGUMENT_EXCEPTION, AuthenticationConstants.Broker.ACCOUNT_CLIENTID_KEY); return; } if (mAuthRequest.getRedirectUri() == null || mAuthRequest.getRedirectUri().isEmpty()) { returnError(ADALError.ARGUMENT_EXCEPTION, AuthenticationConstants.Broker.ACCOUNT_REDIRECT); return; } mRedirectUrl = mAuthRequest.getRedirectUri(); Logger.v(TAG, "OnCreate redirectUrl:" + mRedirectUrl); // Create the Web View to show the page mWebView = (WebView) findViewById( this.getResources().getIdentifier("webView1", "id", this.getPackageName())); Logger.v(TAG, "User agent:" + mWebView.getSettings().getUserAgentString()); mStartUrl = "about:blank"; try { Oauth2 oauth = new Oauth2(mAuthRequest); mStartUrl = oauth.getCodeRequestUrl(); mQueryParameters = oauth.getAuthorizationEndpointQueryParameters(); } catch (UnsupportedEncodingException e) { Log.d(TAG, e.getMessage()); Intent resultIntent = new Intent(); resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_REQUEST_INFO, mAuthRequest); returnToCaller(AuthenticationConstants.UIResponse.BROWSER_CODE_ERROR, resultIntent); return; } // Create the broadcast receiver for cancel Logger.v(TAG, "Init broadcastReceiver with requestId:" + mAuthRequest.getRequestId() + " " + mAuthRequest.getLogInfo()); mReceiver = new ActivityBroadcastReceiver(); mReceiver.mWaitingRequestId = mAuthRequest.getRequestId(); LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(AuthenticationConstants.Browser.ACTION_CANCEL)); String userAgent = mWebView.getSettings().getUserAgentString(); mWebView.getSettings() .setUserAgentString(userAgent + AuthenticationConstants.Broker.CLIENT_TLS_NOT_SUPPORTED); userAgent = mWebView.getSettings().getUserAgentString(); Logger.v(TAG, "UserAgent:" + userAgent); if (isBrokerRequest(getIntent())) { // This activity is started from calling app and running in // Authenticator's process mCallingPackage = getCallingPackage(); Logger.i(TAG, "It is a broker request for package:" + mCallingPackage, ""); if (mCallingPackage == null) { Logger.v(TAG, "startActivityForResult is not used to call this activity"); Intent resultIntent = new Intent(); resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_CODE, AuthenticationConstants.Browser.WEBVIEW_INVALID_REQUEST); resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_MESSAGE, "startActivityForResult is not used to call this activity"); returnToCaller(AuthenticationConstants.UIResponse.BROWSER_CODE_ERROR, resultIntent); return; } mAccountAuthenticatorResponse = getIntent() .getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE); if (mAccountAuthenticatorResponse != null) { mAccountAuthenticatorResponse.onRequestContinued(); } PackageHelper info = new PackageHelper(AuthenticationActivity.this); mCallingPackage = getCallingPackage(); mCallingUID = info.getUIDForPackage(mCallingPackage); String signatureDigest = info.getCurrentSignatureForPackage(mCallingPackage); mStartUrl = getBrokerStartUrl(mStartUrl, mCallingPackage, signatureDigest); if (!isCallerBrokerInstaller()) { Logger.v(TAG, "Caller needs to be verified using special redirectUri"); mRedirectUrl = PackageHelper.getBrokerRedirectUrl(mCallingPackage, signatureDigest); } Logger.v(TAG, "OnCreate redirectUrl:" + mRedirectUrl + " startUrl:" + mStartUrl + " calling package:" + mCallingPackage + " signatureDigest:" + signatureDigest + " current Context Package: " + getPackageName()); } mRegisterReceiver = false; final String postUrl = mStartUrl; Logger.i(TAG, "OnCreate startUrl:" + mStartUrl + " calling package:" + mCallingPackage, " device:" + android.os.Build.VERSION.RELEASE + " " + android.os.Build.MANUFACTURER + android.os.Build.MODEL); setupWebView(mRedirectUrl, mQueryParameters, mAuthRequest); if (savedInstanceState == null) { mWebView.post(new Runnable() { @Override public void run() { // load blank first to avoid error for not loading webview mWebView.loadUrl("about:blank"); mWebView.loadUrl(postUrl); } }); } else { Logger.v(TAG, "Reuse webview"); } }
From source file:net.nym.mutils.ui.test.TestWebViewActivity.java
/** * ?cookie//from www .j a v a 2s. c o m */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) protected void synCookies(Context context, String url) { // ??URI URL uri = null; try { uri = new URL(url); } catch (MalformedURLException e) { try { // ? uri = new URL(MethodNames.HOST_ADDRESS); } catch (MalformedURLException e1) { return; } } CookieManager cookieManager = CookieManager.getInstance(); // cookieManager.removeAllCookie(); cookieManager.setAcceptCookie(true); PersistentCookieStore cookieStore = new PersistentCookieStore(this); if (null != cookieStore) { List<Cookie> cookies = cookieStore.getCookies(); for (Cookie c : cookies) { if (!StringUtils.isNullOrEmpty(c.getName()) && !StringUtils.isNullOrEmpty(c.getValue())) { // cookiesHttpClientcookie StringBuilder cookie = new StringBuilder(c.getName() + "=" + c.getValue()); cookieManager.setCookie(uri.getHost(), cookie.toString());// } } } if (!ContextUtils.isLollipopOrLater()) { CookieSyncManager.getInstance().sync(); } else { cookieManager.flush(); } }
From source file:com.appnexus.opensdk.ANJAMImplementation.java
private static void callRecordEvent(AdWebView webView, Uri uri) { String urlParam = uri.getQueryParameter("url"); if ((urlParam == null) || (!urlParam.startsWith("http"))) { return;/*from w w w . j a va 2 s. com*/ } // Create a invisible webview to fire the url WebView recordEventWebView = new WebView(webView.getContext()); recordEventWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); Clog.d(Clog.baseLogTag, "RecordEvent completed loading: " + url); CookieSyncManager csm = CookieSyncManager.getInstance(); if (csm != null) csm.sync(); } }); recordEventWebView.loadUrl(urlParam); recordEventWebView.setVisibility(View.GONE); webView.addView(recordEventWebView); }
From source file:com.andrewshu.android.reddit.submit.SubmitLinkActivity.java
@Override protected void onPause() { super.onPause(); mSettings.saveRedditPreferences(this); CookieSyncManager.getInstance().stopSync(); }