private void setGResult() { Person signedInUser = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); if (signedInUser != null) { if (signedInUser.hasDisplayName()) { guname = signedInUser.getDisplayName(); } guemail = Plus.AccountApi.getAccountName(mGoogleApiClient); // Toast.makeText(getApplicationContext(),guemail,Toast.LENGTH_LONG).show(); if (signedInUser.hasImage()) { String[] profileparts = signedInUser.getImage().getUrl().split("\\?"); guserProfilePicUrl = profileparts[0]; } if (signedInUser.hasBirthday()) { bday = signedInUser.getBirthday(); Toast.makeText(getApplicationContext(), bday, Toast.LENGTH_LONG).show(); } if (signedInUser.hasGender()) { gender = String.valueOf(signedInUser.getGender()); Toast.makeText(getApplicationContext(), gender, Toast.LENGTH_LONG).show(); } pref = getApplicationContext().getSharedPreferences("unid", MODE_APPEND); SharedPreferences.Editor editor = pref.edit(); editor.putString("unid", guemail); editor.commit(); new Makerqust().execute(); } }
/** * 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()); } }