List of usage examples for android.webkit CookieSyncManager getInstance
public static CookieSyncManager getInstance()
From source file:com.andrewshu.android.reddit.mail.InboxListActivity.java
@Override protected void onResume() { super.onResume(); CookieSyncManager.getInstance().startSync(); int previousTheme = mSettings.getTheme(); boolean previousLoggedIn = mSettings.isLoggedIn(); mSettings.loadRedditPreferences(this, mClient); setRequestedOrientation(mSettings.getRotation()); if (mSettings.getTheme() != previousTheme) { resetUI(mMessagesAdapter);//ww w .j a va 2s . co m } updateNextPreviousButtons(); if (mSettings.isLoggedIn() != previousLoggedIn) { new DownloadMessagesTask(mWhichInbox).execute(Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); } }
From source file:com.kaixin.connect.Kaixin.java
/** * access_token(User-Agent Flow)/*from w w w .jav a 2 s. c o m*/ * * @param context * @param permissions * http://wiki.open.kaixin001.com/index.php?id=OAuth%E6%96% * 87%E6%A1%A3#REST%E6% * 8E%A5%E5%8F%A3%E5%92%8COAuth%E6%9D%83%E9%99%90%E5%AF%B9%E7%85% * A 7%E8%A1%A8 * @param listener * @param redirectUrl * @param responseType */ private void authorize(final Context context, String[] permissions, final KaixinAuthListener listener, final String redirectUrl, String responseType) { CookieSyncManager.createInstance(context); Bundle params = new Bundle(); params.putString("client_id", API_KEY); params.putString("response_type", responseType); params.putString("redirect_uri", redirectUrl); params.putString("state", ""); params.putString("display", "page"); params.putString("oauth_client", "1"); if (permissions != null && permissions.length > 0) { String scope = TextUtils.join(" ", permissions); params.putString("scope", scope); } String url = KX_AUTHORIZE_URL + "?" + Util.encodeUrl(params); if (context .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { Util.showAlert(context, "", ""); } else { new KaixinDialog(context, url, new KaixinDialogListener() { @Override public int onPageBegin(String url) { return KaixinDialogListener.DIALOG_PROCCESS; } @Override public void onPageFinished(String url) { } @Override public boolean onPageStart(String url) { return (KaixinDialogListener.PROCCESSED == parseUrl(url)); } @Override public void onReceivedError(int errorCode, String description, String failingUrl) { listener.onAuthError(new KaixinAuthError(String.valueOf(errorCode), description, failingUrl)); } private int parseUrl(String url) { if (url.startsWith(KX_AUTHORIZE_CALLBACK_URL)) { Bundle values = Util.parseUrl(url); String error = values.getString("error");// if (error != null) { if (ACCESS_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancel(values); } else if (LOGIN_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancelLogin(); } else { listener.onAuthError(new KaixinAuthError(error, error, url)); } Util.clearCookies(context); setAccessToken(null); setRefreshToken(null); setAccessExpires(0L); } else { this.authComplete(values, url); } return KaixinDialogListener.PROCCESSED; } return KaixinDialogListener.UNPROCCESS; } private void authComplete(Bundle values, String url) { CookieSyncManager.getInstance().sync(); String accessToken = values.getString(ACCESS_TOKEN); String refreshToken = values.getString(REFRESH_TOKEN); String expiresIn = values.getString(EXPIRES_IN); if (accessToken != null && refreshToken != null && expiresIn != null) { try { setAccessToken(accessToken); setRefreshToken(refreshToken); setAccessExpiresIn(expiresIn); listener.onAuthComplete(values); } catch (Exception e) { listener.onAuthError( new KaixinAuthError(e.getClass().getName(), e.getMessage(), e.toString())); } } else { listener.onAuthError(new KaixinAuthError("", "", url)); } } }).show(); } }
From source file:com.company.millenium.iwannask.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //GPS/*from w w w . ja v a 2 s . co m*/ locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); locationListener = new LocationListener() { public void onLocationChanged(Location location) { if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Check Permissions Now final int REQUEST_LOCATION = 2; if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Display UI and wait for user interaction } else { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } } else { locationManager.removeUpdates(this); } } public void onStatusChanged(String string, int integer, Bundle bundle) { } public void onProviderEnabled(String string) { } public void onProviderDisabled(String string) { } }; if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Check Permissions Now final int REQUEST_LOCATION = 2; if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Display UI and wait for user interaction } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } } else { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1000, locationListener); } int delay = 30000; // delay for 30 sec. int period = 3000000; // repeat every 5.3min. Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Check Permissions Now final int REQUEST_LOCATION = 2; if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Display UI and wait for user interaction } else { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } } else { locationManager.removeUpdates(locationListener); } } }, delay, period); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); Intent mIntent = getIntent(); URL = Constants.SERVER_URL; if (mIntent.hasExtra("url")) { myWebView = null; startActivity(getIntent()); String url = mIntent.getStringExtra("url"); URL = Constants.SERVER_URL + url; } CookieSyncManager.createInstance(this); CookieSyncManager.getInstance().startSync(); myWebView = (WebView) findViewById(R.id.webview); myWebView.getSettings().setGeolocationDatabasePath(this.getFilesDir().getPath()); myWebView.getSettings().setGeolocationEnabled(true); WebSettings webSettings = myWebView.getSettings(); webSettings.setUseWideViewPort(false); if (!DetectConnection.checkInternetConnection(this)) { webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); showNoConnectionDialog(this); } else { webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); } webSettings.setJavaScriptEnabled(true); myWebView.addJavascriptInterface(new webappinterface(this), "android"); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); myWebView.setOverScrollMode(View.OVER_SCROLL_NEVER); //location test webSettings.setAppCacheEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); myWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { CookieSyncManager.getInstance().sync(); } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); // Ignore SSL certificate errors } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (Uri.parse(url).getHost().equals(Constants.HOST) || Uri.parse(url).getHost().equals(Constants.WWWHOST)) { // This is my web site, so do not override; let my WebView load // the page return false; } // Otherwise, the link is not for a page on my site, so launch // another Activity that handles URLs Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } }); myWebView.setWebChromeClient(new WebChromeClient() { public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); } @Override public void onPermissionRequest(final PermissionRequest request) { Log.d(TAG, "onPermissionRequest"); runOnUiThread(new Runnable() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void run() { if (request.getOrigin().toString().equals("https://apprtc-m.appspot.com/")) { request.grant(request.getResources()); } else { request.deny(); } } }); } public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { // Double check that we don't have any existing callbacks if (mFilePathCallback != null) { mFilePathCallback.onReceiveValue(null); } mFilePathCallback = filePathCallback; // Set up the take picture intent Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File Log.e(TAG, "Unable to create Image File", ex); } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } // Set up the intent to get an existing image Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); // Set up the intents for the Intent chooser Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } }); // setContentView(myWebView); // myWebView.loadUrl(URL); myWebView.loadUrl(URL); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); } }; //CookieManager mCookieManager = CookieManager.getInstance(); //Boolean hasCookies = mCookieManager.hasCookies(); //while(!hasCookies); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); //intent.putExtra("session", session); startService(intent); } Boolean isFirstRun = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("isFirstRun", true); if (isFirstRun) { //show start activity startActivity(new Intent(MainActivity.this, MyIntro.class)); } //if (!isOnline()) // showNoConnectionDialog(this); getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit().putBoolean("isFirstRun", false).commit(); //Pull-to-refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.container); mSwipeRefreshLayout.setOnRefreshListener(this); }
From source file:com.ds.kaixin.Kaixin.java
/** * access_token(User-Agent Flow)//from w ww . ja v a 2 s . c o m * * @param context * @param permissions * ?http://wiki.open.kaixin001.com/index.php?id=OAuth%E6% * 96% 87%E6%A1%A3#REST%E6% * 8E%A5%E5%8F%A3%E5%92%8COAuth%E6%9D%83%E9%99%90%E5%AF%B9%E7%85% * A 7%E8%A1%A8 * @param listener * @param redirectUrl * @param responseType */ private void authorize(final Context context, String[] permissions, final KaixinAuthListener listener, final String redirectUrl, String responseType) { CookieSyncManager.createInstance(context); Bundle params = new Bundle(); params.putString("client_id", API_KEY); params.putString("response_type", responseType); params.putString("redirect_uri", redirectUrl); params.putString("state", ""); params.putString("display", "page"); params.putString("oauth_client", "1"); if (permissions != null && permissions.length > 0) { String scope = TextUtils.join(" ", permissions); params.putString("scope", scope); } String url = KX_AUTHORIZE_URL + "?" + Util.encodeUrl(params); if (context .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { Util.showAlert(context, "", "??"); } else { new KaixinDialog(context, url, new KaixinDialogListener() { public int onPageBegin(String url) { return KaixinDialogListener.DIALOG_PROCCESS; } public void onPageFinished(String url) { } public boolean onPageStart(String url) { return (KaixinDialogListener.PROCCESSED == parseUrl(url)); } public void onReceivedError(int errorCode, String description, String failingUrl) { listener.onAuthError(new KaixinAuthError(String.valueOf(errorCode), description, failingUrl)); } private int parseUrl(String url) { if (url.startsWith(KX_AUTHORIZE_CALLBACK_URL)) { Bundle values = Util.parseUrl(url); String error = values.getString("error");// if (error != null) { if (ACCESS_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancel(values); } else if (LOGIN_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancelLogin(); } else { listener.onAuthError(new KaixinAuthError(error, error, url)); } Util.clearCookies(context); setAccessToken(null); setRefreshToken(null); setAccessExpires(0L); } else { this.authComplete(values, url); } return KaixinDialogListener.PROCCESSED; } return KaixinDialogListener.UNPROCCESS; } private void authComplete(Bundle values, String url) { CookieSyncManager.getInstance().sync(); String accessToken = values.getString(ACCESS_TOKEN); String refreshToken = values.getString(REFRESH_TOKEN); String expiresIn = values.getString(EXPIRES_IN); if (accessToken != null && refreshToken != null && expiresIn != null) { try { setAccessToken(accessToken); setRefreshToken(refreshToken); setAccessExpiresIn(expiresIn); listener.onAuthComplete(values); } catch (Exception e) { listener.onAuthError( new KaixinAuthError(e.getClass().getName(), e.getMessage(), e.toString())); } } else { listener.onAuthError(new KaixinAuthError("", "", url)); } } }).show(); } }
From source file:com.ztspeech.weibo.sdk.kaixin.Kaixin.java
/** * access_token(User-Agent Flow)/*w ww. j a va 2s .c o m*/ * * @param context * @param permissions * http://wiki.open.kaixin001.com/index.php?id=OAuth%E6%96 * % 87%E6%A1%A3#REST%E6% * 8E%A5%E5%8F%A3%E5%92%8COAuth%E6%9D%83%E9%99%90%E5%AF%B9%E7%85% * A 7%E8%A1%A8 * @param listener * @param redirectUrl * @param responseType */ private void authorize(final Context context, String[] permissions, final KaixinAuthListener listener, final String redirectUrl, String responseType) { CookieSyncManager.createInstance(context); Bundle params = new Bundle(); params.putString("client_id", API_KEY); params.putString("response_type", responseType); params.putString("redirect_uri", redirectUrl); params.putString("state", ""); params.putString("display", "page"); params.putString("oauth_client", "1"); if (permissions != null && permissions.length > 0) { String scope = TextUtils.join(" ", permissions); params.putString("scope", scope); } String url = KX_AUTHORIZE_URL + "?" + Util.encodeUrl(params); if (context .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { Util.showAlert(context, "", ""); } else { new KaixinDialog(context, url, new KaixinDialogListener() { @Override public int onPageBegin(String url) { return KaixinDialogListener.DIALOG_PROCCESS; } @Override public void onPageFinished(String url) { } @Override public boolean onPageStart(String url) { return (KaixinDialogListener.PROCCESSED == parseUrl(url)); } @Override public void onReceivedError(int errorCode, String description, String failingUrl) { listener.onAuthError(new KaixinAuthError(String.valueOf(errorCode), description, failingUrl)); } private int parseUrl(String url) { if (url.startsWith(KX_AUTHORIZE_CALLBACK_URL)) { Bundle values = Util.parseUrl(url); String error = values.getString("error");// if (error != null) { if (ACCESS_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancel(values); } else if (LOGIN_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancelLogin(); } else { listener.onAuthError(new KaixinAuthError(error, error, url)); } Util.clearCookies(context); setAccessToken(null); setRefreshToken(null); setAccessExpires(0L); } else { this.authComplete(values, url); } return KaixinDialogListener.PROCCESSED; } return KaixinDialogListener.UNPROCCESS; } private void authComplete(Bundle values, String url) { CookieSyncManager.getInstance().sync(); String accessToken = values.getString(ACCESS_TOKEN); String refreshToken = values.getString(REFRESH_TOKEN); String expiresIn = values.getString(EXPIRES_IN); if (accessToken != null && refreshToken != null && expiresIn != null) { try { setAccessToken(accessToken); setRefreshToken(refreshToken); setAccessExpiresIn(expiresIn); updateStorage(context); listener.onAuthComplete(values); } catch (Exception e) { listener.onAuthError( new KaixinAuthError(e.getClass().getName(), e.getMessage(), e.toString())); } } else { listener.onAuthError(new KaixinAuthError("", "", url)); } } }).show(); } }
From source file:com.microsoft.aad.adal.hello.MainActivity.java
public void onClickClearCookies(View view) { CookieSyncManager.createInstance(MainActivity.this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();//ww w .ja v a2s . c o m CookieSyncManager.getInstance().sync(); }
From source file:com.andrewshu.android.reddit.profile.ProfileActivity.java
@Override protected void onResume() { super.onResume(); CookieSyncManager.getInstance().startSync(); int previousTheme = mSettings.getTheme(); boolean previousLoggedIn = mSettings.isLoggedIn(); mSettings.loadRedditPreferences(this, mClient); setRequestedOrientation(mSettings.getRotation()); if (mSettings.getTheme() != previousTheme) { resetUI(mThingsAdapter);/*w w w . jav a 2 s .c om*/ } updateNextPreviousButtons(); updateKarma(); if (mSettings.isLoggedIn() != previousLoggedIn) { new DownloadProfileTask(mSettings.getUsername()).execute(Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); } }
From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java
@Override protected void onResume() { super.onResume(); // SOPA blackout: Jan 18, 2012 from 8am-8pm EST (1300-0100 UTC) long timeMillis = System.currentTimeMillis(); if (timeMillis >= 1326891600000L && timeMillis <= 1326934800000L) { Toast.makeText(this, "Let's Protest SOPA", Toast.LENGTH_LONG).show(); Common.launchBrowser(this, "http://www.reddit.com", null, false, true, false, false); finish();/*from ww w.j a v a 2s . c o m*/ return; } int previousTheme = mSettings.getTheme(); mSettings.loadRedditPreferences(this, mClient); if (mSettings.getTheme() != previousTheme) { relaunchActivity(); } else { CookieSyncManager.getInstance().startSync(); setRequestedOrientation(mSettings.getRotation()); updateNextPreviousButtons(); if (mThreadsAdapter != null) jumpToThread(); if (mSettings.isLoggedIn()) new PeekEnvelopeTask(this, mClient, mSettings.getMailNotificationStyle()).execute(); } }
From source file:com.example.office365sample.MainActivity.java
public void clearCookies() { CookieSyncManager.createInstance(getApplicationContext()); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();/*w w w.java 2 s. co m*/ CookieSyncManager.getInstance().sync(); }
From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java
@Override protected void onResume() { super.onResume(); int previousTheme = mSettings.getTheme(); mSettings.loadRedditPreferences(this, mClient); if (mSettings.getTheme() != previousTheme) { relaunchActivity();//from w w w . j av a2 s.co m } else { CookieSyncManager.getInstance().startSync(); setRequestedOrientation(mSettings.getRotation()); if (mSettings.isLoggedIn()) new PeekEnvelopeTask(this, mClient, mSettings.getMailNotificationStyle()).execute(); } }