Пример #1
0
  @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;
  }
Пример #2
0
 @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;
     }
   }
 }
  /** 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();
  }
Пример #4
0
 private void googlePlusLogout() {
   if (mGoogleApiClient.isConnected()) {
     Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
     mGoogleApiClient.disconnect();
     mGoogleApiClient.connect();
   }
 }
Пример #5
0
 public void signOutFromGplus() {
   if (mGoogleApiClient.isConnected()) {
     Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
     mGoogleApiClient.disconnect();
     mGoogleApiClient.connect();
     updateUI(false);
   }
 }
  private void onSignOutClicked() {
    if (mGoogleApiClient.isConnected()) {
      Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
      mGoogleApiClient.disconnect();
    }

    showSignedOutUI();
  }
Пример #7
0
  public void disconnect() {

    if (!isConnected() && !isConnecting()) return;

    Plus.AccountApi.clearDefaultAccount(getClient());
    getClient().disconnect();
    connected = false;
    clearAndOnUiThreadTriggerOnConnectListeners(false, -1);
  }
 /** Sign-out from google */
 private void signOutFromGplus() {
   Log.d(TAG, "signOutFromGplus!");
   if (mGoogleApiClient.isConnected()) {
     Log.d(TAG, "signOutFromGplus is connected then disconnecting!");
     Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
     mGoogleApiClient.disconnect();
     mGoogleApiClient.connect();
   }
 }
Пример #9
0
 /** Sign-out from google */
 private void signOutFromGplus() {
   if (mGoogleApiClient.isConnected()) {
     Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
     mGoogleApiClient.disconnect();
     // mGoogleApiClient.connect();
     // updateUI(false);
     SensingController.unregisterAlarm(getApplicationContext());
   }
 }
Пример #10
0
  // [START on_sign_out_clicked]
  private void onSignOutClicked() {
    // Clear the default account so that GoogleApiClient will not automatically
    // connect in the future.
    if (mGoogleApiClient.isConnected()) {
      Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
      mGoogleApiClient.disconnect();
    }

    showSignedOutUI();
  }
Пример #11
0
  // [START on_disconnect_clicked]
  private void onDisconnectClicked() {
    // Revoke all granted permissions and clear the default account.  The user will have
    // to pass the consent screen to sign in again.
    if (mGoogleApiClient.isConnected()) {
      Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
      Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient);
      mGoogleApiClient.disconnect();
    }

    showSignedOutUI();
  }
  @Override
  public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext)
      throws JSONException {
    this.savedCallbackContext = callbackContext;

    if (args.optJSONObject(0) != null) {
      JSONObject obj = args.getJSONObject(0);
      this.webKey = obj.optString(ARGUMENT_WEB_KEY, null);
      this.apiKey = obj.optString(ARGUMENT_ANDROID_KEY, null);
      this.requestOfflineToken = obj.optBoolean(ARGUMENT_OFFLINE_KEY, false);
      this.setupScopes(obj.optString(ARGUMENT_SCOPES, null));
      // possible scope change, so force a rebuild of the client
      this.mGoogleApiClient = null;
    }

    // It's important that we build the GoogleApiClient after setting up scopes so we know which
    // scopes to request when setting up the google services api client.
    buildGoogleApiClient();

    if (ACTION_IS_AVAILABLE.equals(action)) {
      final boolean avail =
          GooglePlayServicesUtil.isGooglePlayServicesAvailable(
                  this.cordova.getActivity().getApplicationContext())
              == 0;
      savedCallbackContext.success("" + avail);

    } else if (ACTION_LOGIN.equals(action)) {
      this.trySilentLogin = false;
      mGoogleApiClient.reconnect();

    } else if (ACTION_TRY_SILENT_LOGIN.equals(action)) {
      this.trySilentLogin = true;
      mGoogleApiClient.reconnect();

    } else if (ACTION_LOGOUT.equals(action)) {
      try {
        Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
        mGoogleApiClient.disconnect();
        // needed in onActivityResult when the connect method below comes back
        loggingOut = true;
        buildGoogleApiClient();
        mGoogleApiClient.connect();
      } catch (IllegalStateException ignore) {
      }
      savedCallbackContext.success("logged out");

    } else if (ACTION_DISCONNECT.equals(action)) {
      disconnect();
    } else {
      return false;
    }
    return true;
  }
Пример #13
0
 public void revokeGplusAccess() {
   if (mGoogleApiClient.isConnected()) {
     Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
     Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient)
         .setResultCallback(
             new ResultCallback<Status>() {
               @Override
               public void onResult(Status arg0) {
                 Log.e(TAG, "User access revoked!");
                 mGoogleApiClient.connect();
                 updateUI(false);
               }
             });
   }
 }
 public static void signOut() {
   if (mGoogleApiClient.isConnected()) {
     Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
     mGoogleApiClient.disconnect();
   }
 }