List of usage examples for android.webkit CookieSyncManager createInstance
public static CookieSyncManager createInstance(Context context)
From source file:com.blueserial.MyApplication.java
@Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); CookieSyncManager.createInstance(this); CookieManager.getInstance().setAcceptCookie(true); }
From source file:com.jaspersoft.android.jaspermobile.cookie.LegacyCookieManager.java
@Override public void semanticConfiguration(String targetDomain) { CookieSyncManager.createInstance(getContext()); final CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeSessionCookie(); cookieManager.setCookie(targetDomain, StringUtils.join(getCookieStore(), ";")); CookieSyncManager.getInstance().sync(); }
From source file:com.swiftkaydevelopment.fullsailcommunicate.fragments.AssignmentViewFragment.java
@Nullable @Override//from ww w .j a v a 2s . co m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mWebView = new WebView(getActivity()); CookieSyncManager.createInstance(getActivity()); CookieSyncManager.getInstance().startSync(); mWebView.getSettings().supportZoom(); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl("https://course.fso.fullsail.edu/class_sections/66645/assignments/1047897"); return mWebView; }
From source file:org.geometerplus.android.fbreader.network.auth.WebAuthorisationScreen.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_PROGRESS); SQLiteCookieDatabase.init(this); CookieSyncManager.createInstance(getApplicationContext()); CookieManager.getInstance().removeAllCookie(); final Intent intent = getIntent(); final Uri data = intent.getData(); if (data == null || data.getHost() == null) { finish();// w ww.j a v a 2 s. co m return; } final String completeUrl = intent.getStringExtra(COMPLETE_URL_KEY); OrientationUtil.setOrientation(this, intent); final WebView view = new WebView(this); view.getSettings().setJavaScriptEnabled(true); view.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { setProgress(progress * 100); } }); view.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { setTitle(url); if (url != null && url.startsWith(completeUrl)) { final HashMap<String, String> cookies = new HashMap<String, String>(); final String cookieString = CookieManager.getInstance().getCookie(url); if (cookieString != null) { // cookieString is a string like NAME=VALUE [; NAME=VALUE] for (String pair : cookieString.split(";")) { final String[] parts = pair.split("=", 2); if (parts.length != 2) { continue; } cookies.put(parts[0].trim(), parts[1].trim()); } } storeCookies(data.getHost(), cookies); WebAuthorisationScreen.this.setResult(RESULT_OK); finish(); } } public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ECLAIR_MR1) { // hack for auth problem in android 2.1 handler.proceed(); } else { super.onReceivedSslError(view, handler, error); } } }); setContentView(view); view.loadUrl(intent.getDataString()); }
From source file:com.polyvi.plugins.weibo.WebViewHandler.java
private void initData() { mWebView.setWebViewClient(new WeiboWebViewClient(mWeiboContent.getRedirectorUrl())); CookieSyncManager.createInstance(mActivity); mWebView.loadUrl(mWeiboContent.getUrl()); }
From source file:thiru.in.basicauthwebview.ShowWebViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_web_view); // Initialize the Cookie Manager CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); String url = "http://auth.thiru.in/"; // Call the REST Service to Authenticate // This is sample app, the app can have a login form, accept input, encode the // id and passowrd using Base64 for Validating AsyncTask<String, Void, CookieStore> cookieStoreTask = new Authenticate(this).execute(url + "app-auth", "ZGVtbzpkZW1v"); //Base64 Encoded for demo:demo try {// www .j a va 2s .co m cookieManager.removeAllCookie(); CookieStore cookieStore = cookieStoreTask.get(); List<Cookie> cookies = cookieStore.getCookies(); // If the User id and password is wrong, the cookie store will not have any cookies // And the page will display 403 Access Denied for (Cookie cookie : cookies) { Log.i("Cookie", cookie.getName() + " ==> " + cookie.getValue()); // Add the REST Service Cookie Responses to Cookie Manager to make it // Available for the WebViewClient cookieManager.setCookie(url, cookie.getName() + "=" + cookie.getValue()); } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } mWebView = (WebView) findViewById(R.id.activity_main_webview); mWebView.setWebViewClient(new WebViewClient()); mWebView.loadUrl(url); }
From source file:com.google.zxing.client.android.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 ww w . j a v a 2 s . c om if (intent == null || (!intent.getAction().equals(Intents.SearchBookContents.ACTION) && !intent.getAction().equals(Intents.SearchBookContents.DEPRECATED_ACTION))) { finish(); return; } mISBN = intent.getStringExtra(Intents.SearchBookContents.ISBN); setTitle(getString(R.string.sbc_name) + ": ISBN " + mISBN); setContentView(R.layout.search_book_contents); mQueryTextView = (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 mQueryTextView.setText(initialQuery); } mQueryTextView.setOnKeyListener(mKeyListener); mQueryButton = (Button) findViewById(R.id.query_button); mQueryButton.setOnClickListener(mButtonListener); mResultListView = (ListView) findViewById(R.id.result_list_view); LayoutInflater factory = LayoutInflater.from(this); mHeaderView = (TextView) factory.inflate(R.layout.search_book_contents_header, mResultListView, false); mResultListView.addHeaderView(mHeaderView); mUserAgent = getString(R.string.zxing_user_agent); }
From source file:com.liato.bankdroid.WebViewActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview);/*from w ww. jav a 2 s . co 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.jaspersoft.android.jaspermobile.network.cookie.CookieHandlerFactory.java
private WebViewCookieStore createWebViewCookieStore(@NonNull Context context) { android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new WebViewCookieStoreLollipop(cookieManager); } else {/* ww w . ja v a2 s . co m*/ CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(context); return new WebViewCookieStorePreLollipop(cookieManager, cookieSyncManager); } }
From source file:com.microsoft.aad.adal.hello.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); CookieSyncManager.createInstance(getApplicationContext()); textView1 = (TextView) findViewById(R.id.textView1); // Clear previous sessions clearSessionCookie();/*from www . j a v a 2 s . c o m*/ try { // Provide key info for Encryption if (Build.VERSION.SDK_INT < 18) { Utils.setupKeyForSample(); } // init authentication Context mAuthContext = new AuthenticationContext(MainActivity.this, Constants.AUTHORITY_URL, false); } catch (Exception e) { Toast.makeText(getApplicationContext(), "Encryption failed", Toast.LENGTH_SHORT).show(); } mEditText = (EditText) findViewById(R.id.editTextUsername); mEditText.setText(""); Toast.makeText(getApplicationContext(), TAG + "done", Toast.LENGTH_SHORT).show(); }