@Override protected void onStop() { super.onStop(); if (mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } }
/** Sign out and disconnect from the APIs. */ public void signOut() { if (!mGoogleApiClient.isConnected()) { // nothing to do debugLog("signOut: was already disconnected, ignoring."); return; } // for Plus, "signing out" means clearing the default account and // then disconnecting if (0 != (mRequestedClients & CLIENT_PLUS)) { debugLog("Clearing default account on PlusClient."); Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); } // For the games client, signing out means calling signOut and // disconnecting if (0 != (mRequestedClients & CLIENT_GAMES)) { debugLog("Signing out from the Google API Client."); Games.signOut(mGoogleApiClient); } // Ready to disconnect debugLog("Disconnecting client."); mConnectOnStart = false; mConnecting = false; mGoogleApiClient.disconnect(); }
@Override public void onResume() { super.onResume(); if (getActivity() instanceof BraintreeListener) { addListener((BraintreeListener) getActivity()); } flushCallbacks(); if (mGoogleApiClient != null && !mGoogleApiClient.isConnected() && !mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } if (mIsBrowserSwitching) { onActivityResult( PayPal.PAYPAL_REQUEST_CODE, Activity.RESULT_FIRST_USER, BraintreeBrowserSwitchActivity.sLastBrowserSwitchResponse); BraintreeBrowserSwitchActivity.sLastBrowserSwitchResponse = null; mIsBrowserSwitching = false; } }
@Override public void onConnectionFailed(ConnectionResult connectionResult) { if (statusesToHandle.contains(connectionResult.getErrorCode())) { GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show(); } if (!gPlusSignInInProgress) { if (gPlusSignInClicked && connectionResult.hasResolution()) { try { gPlusSignInInProgress = true; startIntentSenderForResult( connectionResult.getResolution().getIntentSender(), 0, null, 0, 0, 0); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); gPlusSignInInProgress = false; googleApiClient.connect(); } } else { googleApiClient.disconnect(); if (progressDialog != null) { progressDialog.dismiss(); } } } else { googleApiClient.disconnect(); if (progressDialog != null) { progressDialog.dismiss(); } } }
@Override protected void onStart() { super.onStart(); if (mGoogleApiClient != null && !mGoogleApiClient.isConnected()) { mGoogleApiClient.connect(); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQUEST_ACCOUNT_PICKER: if (resultCode == RESULT_OK) { String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); PrefsManager.setLoggedInAccountEmail(getApplication(), accountName); connectionProgress.show(); if (!Constants.LOCAL_RUN) { initializeApiClient(accountName); apiClient.connect(); } } break; case REQUEST_CODE_RESOLVE_ERR: if (resultCode == RESULT_OK) { connectionResult = null; if (!Constants.LOCAL_RUN) apiClient.connect(); } break; case REQUEST_RECOVER_AUTH: Log.d("TAG", "Recover Auth"); break; } }
protected void onStop() { super.onStop(); if (mGoogleApiClient.isConnected()) { Log.i(TAG, "disconnected"); mGoogleApiClient.disconnect(); } }
@Override protected void onDestroy() { if (client.isConnected()) { client.disconnect(); } super.onDestroy(); }
private void googlePlusLogout() { if (mGoogleApiClient.isConnected()) { Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); mGoogleApiClient.disconnect(); mGoogleApiClient.connect(); } }
@Override protected void onStop() { if (googleApiClient != null && googleApiClient.isConnected()) { googleApiClient.disconnect(); } super.onStop(); }
@AutoFactory public LocationProvider( @Provided GoogleApiAvailability googleApiAvailability, @Provided GoogleApiClient googleApiClient, @Provided FusedLocationProviderApi fusedLocationProviderApi, @Provided LocationManager locationManager, @Provided SensorManager sensorManager, @Provided Display displayManager, Context context, LocationCallback locationCallback) { this.mGoogleApiAvailability = googleApiAvailability; this.mGoogleApiClient = googleApiClient; this.mFusedLocationProviderApi = fusedLocationProviderApi; this.mLocationManager = locationManager; this.mContext = context; this.mLocationCallback = locationCallback; this.mSensorManager = sensorManager; this.mDisplay = displayManager; mLocationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setInterval(INTERVAL_IN_MS) .setFastestInterval(FASTEST_INTERVAL_IN_MS); mNetworkLocationListener = createLocationListener(); mGpsLocationListener = createLocationListener(); determineIfUsingGms(); if (isUsingGms()) { mGoogleApiClient.registerConnectionCallbacks(this); mGoogleApiClient.registerConnectionFailedListener(this); } }
public void desconectar() { if (mGoogleApiClient.isConnected()) { enviarMensagemSair(); apagarDados(); mGoogleApiClient.disconnect(); } }
@Override public void onMessageReceived(MessageEvent messageEvent) { if (!messageEvent.getPath().equalsIgnoreCase(AppConstants.PATH_REQUEST_WEATHER)) return; if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Wearable.API) .build(); } if (!mGoogleApiClient.isConnected()) { ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(LOG_TAG, "Failed to connect to GoogleApiClient."); return; } } Context context = getApplicationContext(); Cursor weatherData = getWearableWeatherData(context); if (weatherData != null && weatherData.moveToFirst()) { // Send Data Item with weather data sendWeatherData(weatherData, context); } else { Log.d(LOG_TAG, "No weather data"); } }
@Override protected void onHandleIntent(Intent intent) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build(); ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "Failed to connect to GoogleApiClient: " + connectionResult.getErrorCode()); return; } // Read all DataItems DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await(); if (!dataItemBuffer.getStatus().isSuccess()) { Log.e(TAG, "Error getting all data items: " + dataItemBuffer.getStatus().getStatusMessage()); } Iterator<DataItem> dataItemIterator = dataItemBuffer.singleRefIterator(); boolean foundArtwork = false; while (dataItemIterator.hasNext()) { DataItem dataItem = dataItemIterator.next(); foundArtwork = foundArtwork || processDataItem(googleApiClient, dataItem); } dataItemBuffer.release(); if (!foundArtwork && intent != null && intent.getBooleanExtra(SHOW_ACTIVATE_NOTIFICATION_EXTRA, false)) { ActivateMuzeiIntentService.maybeShowActivateMuzeiNotification(this); } googleApiClient.disconnect(); }
@Override public void onClick(View v) { if (!mGoogleApiClient.isConnecting()) { // We only process button clicks when GoogleApiClient is not // transitioning between connected and not connected. switch (v.getId()) { case R.id.sign_in_button: mStatus.setText(R.string.status_signing_in); resolveSignInError(); break; case R.id.sign_out_button: // We clear the default account on sign out so that Google // Play services will not return an onConnected callback // without user interaction. Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); mGoogleApiClient.disconnect(); mGoogleApiClient.connect(); break; case R.id.revoke_access_button: // After we revoke permissions for the user with a // GoogleApiClient instance, we must discard it and create a // new one. Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); // Our sample has caches no user data from Google+, however // we would normally register a callback on // revokeAccessAndDisconnect to delete user data so that we // comply with Google developer policies. Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient); mGoogleApiClient = buildGoogleApiClient(); mGoogleApiClient.connect(); break; } } }
@Override public void onPause() { super.onPause(); if (mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RC_SIGN_IN: if (resultCode == RESULT_OK) { // If the error resolution was successful we should continue // processing errors. mSignInProgress = STATE_SIGN_IN; } else { // If the error resolution was not successful or the user // canceled, // we should stop processing errors. mSignInProgress = STATE_DEFAULT; } if (!mGoogleApiClient.isConnecting()) { // If Google Play services resolved the issue with a dialog // then // onStart is not called so we need to re-attempt connection // here. mGoogleApiClient.connect(); } break; } }
@Override public void onDestroy() { super.onDestroy(); if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } }
private void attachRecorder() { if (locationClientAPI == null) { connectToPlayAPI(); } else if (locationClientAPI.isConnected()) { Integer priority = translateDesiredAccuracy(config.getDesiredAccuracy()); LocationRequest locationRequest = LocationRequest.create() .setPriority(priority) // this.accuracy .setFastestInterval(config.getFastestInterval()) .setInterval(config.getInterval()); // .setSmallestDisplacement(config.getStationaryRadius()); LocationServices.FusedLocationApi.requestLocationUpdates( locationClientAPI, locationRequest, this); Log.d( TAG, "- locationUpdateReceiver NOW RECORDING!!!!!!!!!! with priority: " + priority + ", fastestInterval: " + config.getFastestInterval() + ", interval: " + config.getInterval() + ", smallestDisplacement: " + config.getStationaryRadius()); } else { locationClientAPI.connect(); } }
// [START on_connection_failed] @Override public void onConnectionFailed(ConnectionResult connectionResult) { // Could not connect to Google Play Services. The user needs to select an account, // grant permissions or resolve an error in order to sign in. Refer to the javadoc for // ConnectionResult to see possible error codes. Log.d(TAG, "onConnectionFailed:" + connectionResult); if (!mIsResolving && mShouldResolve) { // Log.e(TAG, "Could not resolve ConnectionResult."); if (connectionResult.hasResolution()) { Log.d(TAG, "La conexion tiene solucion."); try { connectionResult.startResolutionForResult(mActivity, RC_SIGN_IN); mIsResolving = false; Log.d(TAG, "Se resuelve:" + RC_SIGN_IN); mShouldResolve = true; mGoogleApiClient.connect(); } catch (IntentSender.SendIntentException e) { Log.e(TAG, "Could not resolve ConnectionResult.", e); mIsResolving = false; mGoogleApiClient.connect(); } } else { Log.e(TAG, "No connectionResult.hasResolution."); // Could not resolve the connection result, show the user an // error dialog. showErrorDialog(connectionResult); } } else { // Show the signed-out UI showSignedOutUI(); } }
private void resolveSignInError() { Log.e(tag, "Has a error. Resolving !"); if (mConnectionResult != null && mConnectionResult.hasResolution()) { Log.e(tag, "ERROR CODE: " + mConnectionResult.getErrorCode()); try { mIntentInProgress = true; ((Activity) mContext) .startIntentSenderForResult( mConnectionResult.getResolution().getIntentSender(), RC_GOOGLE_SIGN_IN, null, 0, 0, 0); } catch (SendIntentException e) { mIntentInProgress = false; mGoogleApiClient.connect(); } } else { Log.d(tag, "mConnectionResult is null:" + (mConnectionResult == null)); mGoogleApiClient.connect(); } }
public void showAchievements() { if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient), 2); } else if (mGoogleApiClient != null) { mGoogleApiClient.connect(); } }
@Override public void onResult(LoadPeopleResult peopleData) { switch (peopleData.getStatus().getStatusCode()) { case CommonStatusCodes.SUCCESS: mListItems.clear(); PersonBuffer personBuffer = peopleData.getPersonBuffer(); try { int count = personBuffer.getCount(); for (int i = 0; i < count; i++) { mListItems.add(personBuffer.get(i).getDisplayName()); } } finally { personBuffer.close(); } mListAdapter.notifyDataSetChanged(); break; case CommonStatusCodes.SIGN_IN_REQUIRED: mGoogleApiClient.disconnect(); mGoogleApiClient.connect(); break; default: Log.e(TAG, "Error when listing people: " + peopleData.getStatus()); break; } }
@Override public void onVisibilityChanged(boolean visible) { Log.d(TAG, "onVisibilityChanged: " + visible); super.onVisibilityChanged(visible); if (visible) { mGoogleApiClient.connect(); registerReceiver(); // Update time zone and date formats, in case they changed while we weren't visible. mCalendar.setTimeZone(TimeZone.getDefault()); } else { unregisterReceiver(); if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } } // Whether the timer should be running depends on whether we're visible (as well as // whether we're in ambient mode), so we may need to start or stop the timer. updateTimer(); }
/** Call this method from your Activity's onStart(). */ public void onStart(Activity act) { mActivity = act; mAppContext = act.getApplicationContext(); debugLog("onStart"); assertConfigured("onStart"); if (mConnectOnStart) { if (mGoogleApiClient.isConnected()) { Log.w(TAG, "GameHelper: client was already connected on onStart()"); } else { debugLog("Connecting client."); mConnecting = true; mGoogleApiClient.connect(); } } else { debugLog("Not attempting to connect becase mConnectOnStart=false"); debugLog("Instead, reporting a sign-in failure."); mHandler.postDelayed( new Runnable() { @Override public void run() { notifyListener(false); } }, 1000); } }
@Override public void onStop() { super.onStop(); Log.d("TAG", "onStop LocationActivity"); mGoogleApiClient.disconnect(); Log.d("TAG", "isConnected ...............: " + mGoogleApiClient.isConnected()); }
@Test @Feature({"GCore"}) public void willUseConnectionBackgroundTest() { int disconnectionTimeout = 5000; int arbitraryNumberOfSeconds = 42; GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient); ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); Activity mockActivity = mock(Activity.class); ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED); helper.setDisconnectionDelay(disconnectionTimeout); // We have a connected client when(mMockClient.isConnected()).thenReturn(true); // We go in the background and extend the delay ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED); ShadowLooper.idleMainLooper(disconnectionTimeout - arbitraryNumberOfSeconds); helper.willUseConnection(); // The client should not have been disconnected. ShadowLooper.idleMainLooper(disconnectionTimeout - arbitraryNumberOfSeconds); verify(mMockClient, never()).disconnect(); // After the full timeout it should still disconnect though ShadowLooper.idleMainLooper(arbitraryNumberOfSeconds); verify(mMockClient).disconnect(); // The client is now disconnected then when(mMockClient.isConnected()).thenReturn(false); // The call should reconnect a disconnected client helper.willUseConnection(); verify(mMockClient).connect(); }
@Override public void run() { // check for STORAGE permission if (!canWriteToStorage()) return; SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(mActivity); String driveAccount = SP.getString( mActivity.getResources().getString(R.string.PROPERTY_googledrive_account), "<Not Set>"); if (driveAccount.equals("<Not Set>")) return; GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mActivity) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .setAccountName(driveAccount) .addConnectionCallbacks(m_me) .addOnConnectionFailedListener(m_me) .build(); googleApiClient.blockingConnect(); if (!googleApiClient.isConnected()) return; if (mTeamNumber >= 0) { syncPhotosForTeam(googleApiClient, mTeamNumber); } else { mRequester = null; // TODO: loop over all folders in the photos dir } }
@Override protected void onPause() { super.onPause(); if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } }
public void signOutFromGplus() { if (mGoogleApiClient.isConnected()) { Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); mGoogleApiClient.disconnect(); mGoogleApiClient.connect(); updateUI(false); } }