Пример #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
  private void getProfileInformation() {
    try {
      if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

        Log.e("GetInfo", currentPerson.toString());

        Gplus_name = currentPerson.getDisplayName();
        Gplus_image = currentPerson.getImage().getUrl();
        Gplus_email = Plus.AccountApi.getAccountName(mGoogleApiClient);
        Gplus_id = currentPerson.getId();
        Log.e("GetInfoID", Gplus_id);

        if (Gplus_id != null) {

          context.runOnUiThread(
              new Runnable() {
                @Override
                public void run() {

                  login_type = "gplus";
                  GlobalClaass.savePrefrencesfor(context, PreferenceConnector.Gplus_ID, Gplus_id);

                  CallFacebookLogin(login_type, Gplus_id, Gplus_email);
                }
              });
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #3
0
  // Called asynchronously -- result of loadPeople() call
  @Override
  public void onResult(People.LoadPeopleResult loadPeopleResult) {
    LOGD(TAG, "onPeopleLoaded, status=" + loadPeopleResult.getStatus().toString());
    if (loadPeopleResult.getStatus().isSuccess()) {
      PersonBuffer personBuffer = loadPeopleResult.getPersonBuffer();
      if (personBuffer != null && personBuffer.getCount() > 0) {
        LOGD(TAG, "Got plus profile for account " + mAccountName);
        Person currentUser = personBuffer.get(0);
        personBuffer.close();

        // Record profile ID, image URL and name
        LOGD(TAG, "Saving plus profile ID: " + currentUser.getId());
        AccountUtils.setPlusProfileId(mAppContext, mAccountName, currentUser.getId());
        String imageUrl = currentUser.getImage().getUrl();
        if (imageUrl != null) {
          imageUrl =
              Uri.parse(imageUrl).buildUpon().appendQueryParameter("sz", "256").build().toString();
        }
        LOGD(TAG, "Saving plus image URL: " + imageUrl);
        AccountUtils.setPlusImageUrl(mAppContext, mAccountName, imageUrl);
        LOGD(TAG, "Saving plus display name: " + currentUser.getDisplayName());
        AccountUtils.setPlusName(mAppContext, mAccountName, currentUser.getDisplayName());
        Person.Cover cover = currentUser.getCover();
        if (cover != null) {
          Person.Cover.CoverPhoto coverPhoto = cover.getCoverPhoto();
          if (coverPhoto != null) {
            LOGD(TAG, "Saving plus cover URL: " + coverPhoto.getUrl());
            AccountUtils.setPlusCoverUrl(mAppContext, mAccountName, coverPhoto.getUrl());
          }
        } else {
          LOGD(TAG, "Profile has no cover.");
        }

        Callbacks callbacks;
        if (null != (callbacks = mCallbacksRef.get())) {
          callbacks.onPlusInfoLoaded(mAccountName);
        }
      } else {
        LOGE(TAG, "Plus response was empty! Failed to load profile.");
      }
    } else {
      LOGE(
          TAG,
          "Failed to load plus proflie, error " + loadPeopleResult.getStatus().getStatusCode());
    }
  }
  /**
   * onConnected is called when our Activity successfully connects to Google Play services.
   * onConnected indicates that an account was selected on the device, that the selected account has
   * granted any requested permissions to our app and that we were able to establish a service
   * connection to Google Play services.
   */
  @Override
  public void onConnected(Bundle connectionHint) {
    final Person user = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

    // The new cordova permission API's are available since Cordova-Android 5,
    // so if you're using API level 23 and want to deploy to Android 6,
    // make sure you're building with Cordova-Android 5 or higher.
    // .. it was either this or adding an Android Support library.
    try {
      Method hasPermissionMethod = cordova.getClass().getMethod("hasPermission", String.class);
      if (hasPermissionMethod != null) {
        if (!(Boolean) hasPermissionMethod.invoke(cordova, Manifest.permission.GET_ACCOUNTS)) {
          Method requestPermissionMethod =
              cordova
                  .getClass()
                  .getMethod("requestPermission", CordovaPlugin.class, int.class, String.class);
          requestPermissionMethod.invoke(
              cordova, this, REQUEST_GET_ACCOUNTS, Manifest.permission.GET_ACCOUNTS);
        }
      }
    } catch (Exception ignore) {
    }

    this.email = Plus.AccountApi.getAccountName(mGoogleApiClient);
    this.result = new JSONObject();

    try {
      result.put("email", email);
      // in case there was no internet connection, this may be null
      if (user != null) {
        result.put("userId", user.getId());
        result.put("displayName", user.getDisplayName());
        result.put("gender", getGender(user.getGender()));
        if (user.getImage() != null) {
          result.put("imageUrl", user.getImage().getUrl());
        }
        if (user.getName() != null) {
          result.put("givenName", user.getName().getGivenName());
          result.put("middleName", user.getName().getMiddleName());
          result.put("familyName", user.getName().getFamilyName());
          if (user.hasAgeRange()) {
            if (user.getAgeRange().hasMin()) {
              result.put("ageRangeMin", user.getAgeRange().getMin());
            }
            if (user.getAgeRange().hasMax()) {
              result.put("ageRangeMax", user.getAgeRange().getMax());
            }
          }
          if (user.hasBirthday()) {
            result.put("birthday", user.getBirthday());
          }
        }
      }
      resolveToken(email, result);
    } catch (JSONException e) {
      savedCallbackContext.error("result parsing trouble, error: " + e.getMessage());
    }
  }
Пример #5
0
 public void startGoogleLogin(LoginListener googleLoginListener) {
   this.googleLoginListener = googleLoginListener;
   if (googleConnectionResult != null && googleConnectionResult.hasResolution()) {
     try {
       googleConnectionResult.startResolutionForResult(activity, ACTIVITY_GOOGLE_CONNECTION);
     } catch (IntentSender.SendIntentException e) {
       googleConnectionResult = null;
       googleClient.connect();
     }
   } else if (googleClient.isConnected()) {
     googleConnectionResult = null;
     Person user = Plus.PeopleApi.getCurrentPerson(googleClient);
     Log.i("Menyou", "Google logged in: " + user);
     googleLoginListener.onSuccess(user.getId(), user.getName().getFormatted(), null, null);
     this.googleLoginListener = null;
   } else {
     googleConnectionResult = null;
     googleClient.connect();
   }
 }
Пример #6
0
  /** Fetching user's information name, email, profile picture */
  private void getGGProfileInformation() {
    Log.e(tag, "getGGProfileInformation");
    try {
      if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
        String personGooglePlusProfile = currentPerson.getUrl();

        Log.e(tag, currentPerson.toString());

        String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
        String id = currentPerson.getId();
        String name = new String(currentPerson.getDisplayName().getBytes("UTF-8"), "UTF-8");
        String birthday = "";
        if (currentPerson.getBirthday() != null) {
          birthday = currentPerson.getBirthday();
        }
        String gender = currentPerson.getGender() == 1 ? "men" : "women";
        String avatar = currentPerson.getImage().getUrl();
        Log.e(
            tag,
            "Name: "
                + name
                + ", plusProfile: "
                + personGooglePlusProfile
                + ", email: "
                + email
                + ", Image: "
                + avatar
                + ", birthday: "
                + birthday);

        new GGLoginTask().execute(name, email, avatar, gender, birthday, id);
      } else {
        Log.e(tag, "Person information is null");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #7
0
  public Person getCurrentPerson() {

    if (!isConnected()) {
      return null;
    }

    Person person = null;
    String id = "";
    String name = "";
    int gender = Person.GENDER_UNCLASSIFIED;
    String email = "";
    String profileImageLink = "";

    try {

      com.google.android.gms.plus.model.people.Person currentPerson =
          Plus.PeopleApi.getCurrentPerson(getClient());
      id = currentPerson.getId();
      name = currentPerson.getDisplayName();
      gender = currentPerson.getGender();
      email = Plus.AccountApi.getAccountName(getClient());
      profileImageLink = currentPerson.getImage().getUrl();

      if (id == null) id = "";
      if (name == null) name = "";
      if (email == null) email = "";
      if (profileImageLink == null) profileImageLink = "";

      person = new Person(id, name, gender, email, profileImageLink);

    } catch (Exception e) {
      e.printStackTrace();
    }

    return person;
  }
Пример #8
0
  /** Fetching user's information name, email, profile pic */
  private void getProfileInformation() {
    try {
      if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
        // Log.d("getAboutMe", currentPerson.getAboutMe());
        // Log.d("getBirthday", currentPerson.getBirthday());
        // Log.d("getBraggingRights",
        // currentPerson.getBraggingRights());
        // Log.d("getCurrentLocation",
        // currentPerson.getCurrentLocation());
        // Log.d("getDisplayName", currentPerson.getDisplayName());
        // Log.d("getId", currentPerson.getId());
        // Log.d("getLanguage", currentPerson.getLanguage());
        // Log.d("getNickname", currentPerson.getNickname());
        // Log.d("getTagline", currentPerson.getTagline());
        // Log.d("getUrl", currentPerson.getUrl());
        // Log.d("getAgeRange", "" + currentPerson.getAgeRange());
        // Log.d("getCircledByCount",
        // "" + currentPerson.getCircledByCount());
        // Log.d("getCover", "" + currentPerson.getCover());
        // Log.d("getUrls", "" + currentPerson.getUrls());
        // Log.d("getPlacesLived", "" + currentPerson.getPlacesLived());
        // Log.d("getOrganizations", "" +
        // currentPerson.getOrganizations());
        // Log.d("getName", "" + currentPerson.getName());
        // Log.d("getGender", "" + currentPerson.getGender());
        //                Toast.makeText(LoginActivity.this, currentPerson.getDisplayName(),
        // Toast.LENGTH_LONG).show();
        loginName = currentPerson.getDisplayName();
        loginId = currentPerson.getId();
        loginImageUrl = currentPerson.getImage().getUrl();

        loginEmail = Plus.AccountApi.getAccountName(mGoogleApiClient);

        if (AppConstant.isNetworkAvailable(LoginActivity.this)) {
          loginType = 3;
          new LoginTask(loginId, loginName, loginEmail, loginImageUrl, 3).execute();
        } else {
          AppConstant.showNetworkError(LoginActivity.this);
        }

        /*
          Log.e(TAG, "Name: " + personName + ", plusProfile: "
                  + personGooglePlusProfile + ", email: " + email
                  + ", Image: " + personPhotoUrl);

          // by default the profile url gives 50x50 px image only
          // we can replace the value with whatever dimension we want by
          // replacing sz=X
        /* personPhotoUrl = personPhotoUrl.substring(0,
                  personPhotoUrl.length() - 2)
                  + PROFILE_PIC_SIZE;*/
        // email = "";
        //                if (email.equals("")) {
        //                    AppConstant
        //                            .singleButtonAlertDialog(
        //                                    LoginActivity.this,
        //                                    "Error",
        //                                    "Unable to find Email Address from Google Plus.So
        // please register with us  to use this application.");
        //
        //                } else {
        //                    new LoginTask(LoginActivity.this, true, false, personName,
        //                            email, id, personPhotoUrl, dob,
        //                            shouldShowMainActivity, "").execute();
        //                }
      } else {
        Toast.makeText(getApplicationContext(), "Person information is null", Toast.LENGTH_LONG)
            .show();
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (null != dialog) {
        if (dialog.isShowing()) {
          dialog.dismiss();
        }
      }
    }
  }