@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 onPause() { super.onPause(); if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } }
@Override protected void onDestroy() { if (client.isConnected()) { client.disconnect(); } super.onDestroy(); }
@Override public void onPause() { super.onPause(); if (mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } }
/** * Handle activity result. Call this method from your Activity's onActivityResult callback. If the * activity result pertains to the sign-in process, processes it appropriately. */ public void onActivityResult(int requestCode, int responseCode, Intent intent) { debugLog( "onActivityResult: req=" + (requestCode == RC_RESOLVE ? "RC_RESOLVE" : String.valueOf(requestCode)) + ", resp=" + GooglePlayServicesGameHelperUtils.activityResponseCodeToString(responseCode)); if (requestCode != RC_RESOLVE) { debugLog("onActivityResult: request code not meant for us. Ignoring."); return; } // no longer expecting a resolution mExpectingResolution = false; if (!mConnecting) { debugLog("onActivityResult: ignoring because we are not connecting."); return; } // We're coming back from an activity that was launched to resolve a // connection problem. For example, the sign-in UI. if (responseCode == Activity.RESULT_OK) { // Ready to try to connect again. debugLog("onAR: Resolution was RESULT_OK, so connecting current client again."); connect(); } else if (responseCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) { debugLog("onAR: Resolution was RECONNECT_REQUIRED, so reconnecting."); connect(); } else if (responseCode == Activity.RESULT_CANCELED) { // User cancelled. debugLog("onAR: Got a cancellation result, so disconnecting."); mSignInCancelled = true; mConnectOnStart = false; mUserInitiatedSignIn = false; mSignInFailureReason = null; // cancelling is not a failure! mConnecting = false; mGoogleApiClient.disconnect(); // increment # of cancellations int prevCancellations = getSignInCancellations(); int newCancellations = incrementSignInCancellations(); debugLog( "onAR: # of cancellations " + prevCancellations + " --> " + newCancellations + ", max " + mMaxAutoSignInAttempts); notifyListener(false); } else { // Whatever the problem we were trying to solve, it was not // solved. So give up and show an error message. debugLog( "onAR: responseCode=" + GooglePlayServicesGameHelperUtils.activityResponseCodeToString(responseCode) + ", so giving up."); giveUp(new SignInFailureReason(mConnectionResult.getErrorCode(), responseCode)); } }
@Override public void onConnected(Bundle bundle) { gPlusEmail = Plus.AccountApi.getAccountName(googleApiClient); Person person = Plus.PeopleApi.getCurrentPerson(googleApiClient); if (person != null) { if (person.hasName()) { gPlusFullName = ""; if (person.getName().hasGivenName()) { gPlusFullName += person.getName().getGivenName() + " "; } if (person.getName().hasMiddleName()) { gPlusFullName += person.getName().getMiddleName() + " "; } if (person.getName().hasFamilyName()) { gPlusFullName += person.getName().getFamilyName(); } } if (person.hasId()) { gPlusId = person.getId(); } } if (gPlusSignInClicked) { Log.d("LOGIN", "Starting Authentication Service..."); } else { Plus.AccountApi.clearDefaultAccount(googleApiClient); Plus.AccountApi.clearDefaultAccount(googleApiClient); googleApiClient.disconnect(); } gPlusSignInClicked = false; }
@Override protected void onPause() { super.onPause(); if (googleApiClient != null) { googleApiClient.disconnect(); } }
@Override protected void onStop() { if (googleApiClient != null && googleApiClient.isConnected()) { googleApiClient.disconnect(); } super.onStop(); }
protected void onStop() { super.onStop(); if (mGoogleApiClient.isConnected()) { Log.i(TAG, "disconnected"); mGoogleApiClient.disconnect(); } }
@Override public void onDetach() { super.onDetach(); mSelectedAccount = null; mGoogleApiClient.disconnect(); mGoogleApiClient = null; }
private void googlePlusLogout() { if (mGoogleApiClient.isConnected()) { Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); mGoogleApiClient.disconnect(); mGoogleApiClient.connect(); } }
@Override public void onResult(DataApi.DeleteDataItemsResult deleteDataItemsResult) { if (!deleteDataItemsResult.getStatus().isSuccess()) { Log.e(TAG, "dismissWearableNotification(): failed to delete DataItem"); } mGoogleApiClient.disconnect(); }
public void desconectar() { if (mGoogleApiClient.isConnected()) { enviarMensagemSair(); apagarDados(); mGoogleApiClient.disconnect(); } }
@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 protected void onStop() { super.onStop(); mGoogleApiClient.disconnect(); unregisterReceiver(mConnectionReceiver); }
@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 onCancel() { mGoogleApiClient.disconnect(); String title = getString(R.string.app_name); // initialize the notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.mipmap.ic_launcher_logo) .setContentTitle(title) .setContentText(getString(R.string.alarm_cancelled)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setAutoCancel(true); Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // allows you to update the notification later on. if (!declined) { mNotificationManager.notify(AlarmNotifier.notificationID, mBuilder.build()); String text = getString(R.string.alarm_cancelled); Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG); toast.show(); } finish(); }
@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; } }
public void disconnect() { if (isGooglePlayServicesAvailable()) { apiClient.disconnect(); } else { listener.onDisconnected(); } }
/** 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 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(); }
@Override public void onDestroy() { super.onDestroy(); if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } }
/** * Kills a session and it's underlying media player * * @param callback */ public void kill(final ChromecastSessionCallback callback) { // this.mRemoteMediaPlayer.stop(mApiClient).setResultCallback(new // ResultCallback<RemoteMediaPlayer.MediaChannelResult>() { // @Override // public void onResult(MediaChannelResult result) { // try { // Cast.CastApi.stopApplication(mApiClient); // mApiClient.disconnect(); // } catch(Exception e) { // // } // // callback.onSuccess(); // } // }); try { Cast.CastApi.stopApplication(mApiClient); mApiClient.disconnect(); } catch (Exception e) { } callback.onSuccess(); // Cast.CastApi.stopApplication(mApiClient); }
@Override protected void onStop() { super.onStop(); if (mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } }
@Override public void onStop() { super.onStop(); Log.d("TAG", "onStop LocationActivity"); mGoogleApiClient.disconnect(); Log.d("TAG", "isConnected ...............: " + mGoogleApiClient.isConnected()); }
public void signOutFromGplus() { if (mGoogleApiClient.isConnected()) { Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); mGoogleApiClient.disconnect(); mGoogleApiClient.connect(); updateUI(false); } }
@Override public void onStop() { // Tear down GoogleApiClient if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } super.onStop(); }
@Override protected void onPause() { super.onPause(); if (mGoogleApiClient != null) Wearable.DataApi.removeListener(mGoogleApiClient, this); if (mSensorManager != null) mSensorManager.unregisterListener(this); if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) mGoogleApiClient.disconnect(); if (mHeadTracker != null) mHeadTracker.stopTracking(); }
@Override protected void onPause() { super.onPause(); if (mGoogleApiClient.isConnected()) { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this); mGoogleApiClient.disconnect(); } }
@Override public void onStop() { super.onStop(); if (mGoogleApiClient != null) { mGoogleApiClient.disconnect(); } }