/** Fetching user's information name, email, profile pic */ private void getProfileInformation() { try { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); personName = currentPerson.getDisplayName(); String personPhotoUrl = currentPerson.getImage().getUrl(); String personGooglePlusProfile = currentPerson.getUrl(); email = Plus.AccountApi.getAccountName(mGoogleApiClient); Log.e( TAG, "Name: " + personName + ", plusProfile: " + personGooglePlusProfile + ", email: " + email + ", Image: " + personPhotoUrl); } else { Toast.makeText(getApplicationContext(), "Person information is null", Toast.LENGTH_LONG) .show(); } } catch (Exception e) { e.printStackTrace(); } }
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(); } }
public void checkuser() { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String email = Plus.AccountApi.getAccountName(mGoogleApiClient); String personName = currentPerson.getDisplayName(); try { long timeInMillis = System.currentTimeMillis(); final String PhoneModel = android.os.Build.MODEL; JSONObject userData = new JSONObject(); userData.put("phoneModel", PhoneModel); userData.put("username", personName); userData.put("email", email); Log.d(TAG, userData.toString()); String response = CommonFunctions.sendRequestToServer(userData.toString(), "login"); if (response.contains("SUCCESS") || response.contains("ALREADY")) { Log.d("testing", response); String userid = response.subSequence(13, 17).toString(); // Log.d("testing", userid); saveSharedString("USERID", userid); // initialsetup(); // SensingController.unregisterAlarm(getApplicationContext()); } } catch (Exception e) { Log.e(TAG, e.toString()); } }
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(); } }
@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; }
private void updateUI(boolean isSignedIn) { if (isSignedIn) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); if (currentPerson != null) { // Show signed-in user's name String name = currentPerson.getDisplayName(); mStatus.setText(getString(R.string.signed_in_fmt, name)); // Show users' email address (which requires GET_ACCOUNTS permission) if (checkAccountsPermission()) { String currentAccount = Plus.AccountApi.getAccountName(mGoogleApiClient); ((TextView) recViewLogin.findViewById(R.id.email)).setText(currentAccount); } } else { // If getCurrentPerson returns null there is generally some error with the // configuration of the application (invalid Client ID, Plus API not enabled, etc). Log.w(TAG, getString(R.string.error_null_person)); mStatus.setText(getString(R.string.signed_in_err)); } // Set button visibility recViewLogin.findViewById(R.id.sign_in_button).setVisibility(View.GONE); recViewLogin.findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE); } else { // Show signed-out message and clear email field mStatus.setText(R.string.signed_out); ((TextView) recViewLogin.findViewById(R.id.email)).setText(""); // Set button visibility recViewLogin.findViewById(R.id.sign_in_button).setEnabled(true); recViewLogin.findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE); recViewLogin.findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE); } }
@Override public void onConnected(Bundle bundle) { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String personName = currentPerson.getDisplayName(); String personPhoto = currentPerson.getImage().getUrl(); String firstName = currentPerson.getName().getGivenName(); String lastName = currentPerson.getName().getFamilyName(); String personGooglePlusProfile = currentPerson.getUrl(); String date = currentPerson.getBirthday(); if (date == null) { date = ""; } int gender = currentPerson.getGender(); String email = Plus.AccountApi.getAccountName(mGoogleApiClient); Intent mIntent = new Intent(getActivity(), LoginUserDetails.class); mIntent.putExtra("login_method", "google"); mIntent.putExtra("email", email); mIntent.putExtra("first_name", firstName); mIntent.putExtra("gender", gender); mIntent.putExtra("last_name", lastName); mIntent.putExtra("photo", personPhoto); mixpanel.track("Login - Google"); startActivity(mIntent); } else { Toast.makeText(getContext(), "You do not have a google+ account", Toast.LENGTH_SHORT).show(); showSocialLoginDialog(); } Log.d(TAG, "onConnected:" + bundle); mShouldResolve = false; }
/** * 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()); } }
/** * Fetching user's information name, email, profile pic * */ private void getProfileInformation() { try { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String personName = currentPerson.getDisplayName(); String personPhotoUrl = currentPerson.getImage().getUrl(); String personGooglePlusProfile = currentPerson.getUrl(); String email = Plus.AccountApi.getAccountName(mGoogleApiClient); Log.e( TAG, "Name: " + personName + ", plusProfile: " + personGooglePlusProfile + ", email: " + email + ", Image: " + personPhotoUrl); Toast.makeText( getApplicationContext(), "Signed In as:" + currentPerson.getDisplayName(), Toast.LENGTH_LONG) .show(); if (!sharedPref.contains("UID")) { int Applicationid = getUID(); saveSharedint("UID", Applicationid); } long DS = getDataValue(context); long DC = getFolderSize() + DS; String DataS = l2bytes(DS, false); String DataC = l2bytes(DC, false); long hours = CommonUtils.totaltime / 3600; long minutes = (CommonUtils.totaltime % 3600) / 60; long seconds = (long) ((CommonUtils.totaltime % 3600) % 60); txtDatasent.setText("Data Sent :" + DataS); txtDatasent.setAnimation(null); } else { Toast.makeText(getApplicationContext(), "Person information is null", Toast.LENGTH_LONG) .show(); } } catch (Exception e) { e.printStackTrace(); } }
public static String getAuthToken(Context context) { if (!mGoogleApiClient.isConnected()) { mGoogleApiClient.connect(); } String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient); Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE); String scopes = "audience:server:client_id:" + SERVER_CLIENT_ID; // Not the app's client ID. try { return GoogleAuthUtil.getToken(context, account, scopes); } catch (IOException e) { Log.e(TAG, "Error retrieving ID token.", e); return null; } catch (GoogleAuthException e) { Log.e(TAG, "Error retrieving ID token.", e); return null; } }
public boolean requestlogout() { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String email = Plus.AccountApi.getAccountName(mGoogleApiClient); String response = null; try { JSONObject userData = new JSONObject(); userData.put("email", email); Log.d(TAG, userData.toString()); response = CommonFunctions.sendRequestToServer(userData.toString(), "logout"); if (response.contains("DONE")) { return true; } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }
private void showSignedInUI() { // set current user String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient); Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE); User.setCurrentUser(new User(account.name, account.name, "0", "0")); // Send Authentication Token to server and set current User new GetUserIDTask().execute(); setContentView(R.layout.activity_myrides); if (savedInstanceState == null) { activityFragment = new MyRidesFragment(); getSupportFragmentManager() .beginTransaction() .add(R.id.container, (activityFragment)) .commit(); } signedIn = true; invalidateOptionsMenu(); }
@Override public void onConnected(Bundle bundle) { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { BrewSharedPrefs.setIsUserLoggedIn(true); Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); BrewSharedPrefs.setFullName(currentPerson.getDisplayName()); String personPhoto = currentPerson.getImage().getUrl(); try { URL url = new URL(personPhoto); personPhoto = personPhoto.replace(url.getQuery(), ""); } catch (MalformedURLException e) { e.printStackTrace(); } BrewSharedPrefs.setGoolgePlusProfileUrl(currentPerson.getUrl()); BrewSharedPrefs.setUserProfileImageUrl(personPhoto); BrewSharedPrefs.setEmailAddress(Plus.AccountApi.getAccountName(mGoogleApiClient)); PlusAccountSetup(); } }
private void handleSignInSuccess() { Person currentPerson = Plus.PeopleApi.getCurrentPerson(this.googleApiClient); if (currentPerson != null) { User user = new User(); user.setName(currentPerson.getName().getGivenName()); user.setSurname(currentPerson.getName().getFamilyName()); user.setAuthenticationType(AuthenticationType.Google); String photoUrl = currentPerson.getImage().getUrl(); photoUrl = photoUrl.replace("?sz=50", "?sz=100"); user.setPhotoUrl(photoUrl); String email = Plus.AccountApi.getAccountName(this.googleApiClient); user.setEmail(email); // We took necessary the google account information, now we save the user into our database // with an id // The authentication service will handle the rest (operation success and failure situations) this.authenticationServiceProxy.saveUser(user); } }
public void getProfileInformation() { try { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String personName = currentPerson.getDisplayName(); String personPhotoUrl = currentPerson.getImage().getUrl(); String personGooglePlusProfile = currentPerson.getUrl(); String email = Plus.AccountApi.getAccountName(mGoogleApiClient); Log.e( TAG, "Name: " + personName + ", plusProfile: " + personGooglePlusProfile + ", email: " + email + ", Image: " + personPhotoUrl); profileName.setText(personName); profileEmail.setText(email); // 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; new LoadProfileImage(imgProfilePic).execute(personPhotoUrl); } else { Toast.makeText(getApplicationContext(), "Person information is null", Toast.LENGTH_LONG) .show(); } } catch (Exception e) { e.printStackTrace(); } }
/** 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(); } }
private void getProfileInformation() { try { if (Plus.PeopleApi.getCurrentPerson(googleApiClient) != null) { String accountName = Plus.AccountApi.getAccountName(googleApiClient); String avatarUrl = Plus.PeopleApi.getCurrentPerson(googleApiClient).getImage().getUrl(); String id = Plus.PeopleApi.getCurrentPerson(googleApiClient).getId(); // String coverUrl = // Plus.PeopleApi.getCurrentPerson(googleApiClient).getCover().getCoverPhoto().getUrl(); User user = new User(this); user.setAccountName(accountName); user.setAvatarUrl(avatarUrl); user.setGoogleId(id); getGoogleAuthToken(); } } catch (Exception e) { Log.i("jbefb", e.getMessage()); e.printStackTrace(); } // Toast.makeText(LoginActivity.this, "Google SignIn Success", Toast.LENGTH_SHORT).show(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (isFbLogin) { callbackManager.onActivityResult(requestCode, resultCode, data); } if (requestCode == REQUEST_CODE_TOKEN_AUTH && resultCode == RESULT_OK) { // We had to sign in - now we can finish off the token request. new GoogleAuthTokenTask().execute(Plus.AccountApi.getAccountName(googleApiClient)); } if (requestCode == RC_SIGN_IN & isSignInClicked) { if (resultCode != RESULT_OK) { isSignInClicked = false; } intentInProgress = false; if (!googleApiClient.isConnecting()) { googleApiClient.connect(); } } }
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; }
private void getGoogleAuthToken() { new GoogleAuthTokenTask().execute(Plus.AccountApi.getAccountName(googleApiClient)); }
/** 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(); } } } }