Java Code Examples for com.google.firebase.auth.FirebaseUser#getEmail()

The following examples show how to use com.google.firebase.auth.FirebaseUser#getEmail() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From snippets-android with Apache License 2.0 8 votes vote down vote up
public void getUserProfile() {
    // [START get_user_profile]
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        // Name, email address, and profile photo Url
        String name = user.getDisplayName();
        String email = user.getEmail();
        Uri photoUrl = user.getPhotoUrl();

        // Check if user's email is verified
        boolean emailVerified = user.isEmailVerified();

        // The user's ID, unique to the Firebase project. Do NOT use this value to
        // authenticate with your backend server, if you have one. Use
        // FirebaseUser.getIdToken() instead.
        String uid = user.getUid();
    }
    // [END get_user_profile]
}
 
Example 2
Source File: MainActivity.java    From protrip with MIT License 7 votes vote down vote up
private void onSignedInInitialize(FirebaseUser firebaseUser) {

        //Firebase Auth
        User user = new User(firebaseUser.getDisplayName(),
                firebaseUser.getPhotoUrl(),
                firebaseUser.getEmail(), firebaseUser.getUid());
        mUsername = user.getUsername();
        mUserAvatarUrl = user.getAvatarUrl();
        mUserEmail = user.getEmailId();
        mUid = user.getUid();
        tvUserName.setText(mUsername);
        tvUserEmail.setVisibility(View.VISIBLE);
        tvUserEmail.setText(mUserEmail);
        logoutItem.setVisible(true);
        favoritesItem.setVisible(true);
        if (mUserAvatarUrl != null) {
            Picasso.with(this).load(mUserAvatarUrl).
                    placeholder(R.drawable.ic_account_circle_white_24dp).
                    transform(new CircleTransform()).
                    fit().
                    into(ivAvatar);
        }


    }
 
Example 3
Source File: AddUserInteractor.java    From FirebaseMessagingApp with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addUserToDatabase(final Context context, FirebaseUser firebaseUser) {
    DatabaseReference database = FirebaseDatabase.getInstance().getReference();
    User user = new User(firebaseUser.getUid(),
            firebaseUser.getEmail(),
            new SharedPrefUtil(context).getString(Constants.ARG_FIREBASE_TOKEN));
    database.child(Constants.ARG_USERS)
            .child(firebaseUser.getUid())
            .setValue(user)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        mOnUserDatabaseListener.onSuccess(context.getString(R.string.user_successfully_added));
                    } else {
                        mOnUserDatabaseListener.onFailure(context.getString(R.string.user_unable_to_add));
                    }
                }
            });
}
 
Example 4
Source File: PlaceDetailActivity.java    From protrip with MIT License 6 votes vote down vote up
private void onSignedInInitialize(FirebaseUser firebaseUser) {
    User user = new User(firebaseUser.getDisplayName(),
            firebaseUser.getPhotoUrl(),
            firebaseUser.getEmail(),
            firebaseUser.getUid());

    mUsername = user.getUsername();
    mUserAvatarUrl = user.getAvatarUrl();
    mUserEmail = user.getEmailId();
    mUid = user.getUid();

    mFavsDbRef = mFirebaseDatabase.getReference().getRoot().child(mUid + "/favoritePlaces");
    isFavourite(this, place_id);
}
 
Example 5
Source File: AddUserInteractor.java    From firebase-chat with MIT License 6 votes vote down vote up
@Override
public void addUserToDatabase(final Context context, FirebaseUser firebaseUser) {
    DatabaseReference database = FirebaseDatabase.getInstance().getReference();
    User user = new User(firebaseUser.getUid(),
            firebaseUser.getEmail(),
            new SharedPrefUtil(context).getString(Constants.ARG_FIREBASE_TOKEN));
    database.child(Constants.ARG_USERS)
            .child(firebaseUser.getUid())
            .setValue(user)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        mOnUserDatabaseListener.onSuccess(context.getString(R.string.user_successfully_added));
                    } else {
                        mOnUserDatabaseListener.onFailure(context.getString(R.string.user_unable_to_add));
                    }
                }
            });
}
 
Example 6
Source File: UserModel.java    From openwebnet-android with MIT License 6 votes vote down vote up
private Builder(FirebaseUser firebaseUser) {
    this.userId = firebaseUser.getUid();
    this.email = firebaseUser.getEmail();
    this.name = firebaseUser.getDisplayName();
    this.phoneNumber = firebaseUser.getPhoneNumber();
    this.photoUrl = firebaseUser.getPhotoUrl() == null ? null : firebaseUser.getPhotoUrl().toString();

    // https://stackoverflow.com/questions/4212320/get-the-current-language-in-device
    this.iso3Language = Locale.getDefault().getISO3Language();
    this.iso3Country = Locale.getDefault().getISO3Country();
    this.locale = ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).toLanguageTags();

    this.createdAt = firebaseUser.getMetadata() != null ?
        new Date(firebaseUser.getMetadata().getCreationTimestamp()) : new Date();
    this.modifiedAt = new Date();
}
 
Example 7
Source File: CredentialUtils.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Build a credential for the specified {@link FirebaseUser} with optional password and {@link
 * IdpResponse}.
 * <p>
 * If the credential cannot be built (for example, empty email) then will return {@code null}.
 */
@Nullable
public static Credential buildCredential(@NonNull FirebaseUser user,
                                         @Nullable String password,
                                         @Nullable String accountType) {
    String email = user.getEmail();
    String phone = user.getPhoneNumber();
    Uri profilePictureUri =
            user.getPhotoUrl() == null ? null : Uri.parse(user.getPhotoUrl().toString());

    if (TextUtils.isEmpty(email) && TextUtils.isEmpty(phone)) {
        Log.w(TAG, "User (accountType=" + accountType + ") has no email or phone number, cannot build credential.");
        return null;
    }
    if (password == null && accountType == null) {
        Log.w(TAG, "User has no accountType or password, cannot build credential.");
        return null;
    }

    Credential.Builder builder =
            new Credential.Builder(TextUtils.isEmpty(email) ? phone : email)
                    .setName(user.getDisplayName())
                    .setProfilePictureUri(profilePictureUri);

    if (TextUtils.isEmpty(password)) {
        builder.setAccountType(accountType);
    } else {
        builder.setPassword(password);
    }

    return builder.build();
}
 
Example 8
Source File: Rating.java    From firestore-android-arch-components with Apache License 2.0 5 votes vote down vote up
public Rating(FirebaseUser user, double rating, String text) {
    this.userId = user.getUid();
    this.userName = user.getDisplayName();
    if (TextUtils.isEmpty(this.userName)) {
        this.userName = user.getEmail();
    }

    this.rating = rating;
    this.text = text;
}
 
Example 9
Source File: Rating.java    From friendlyeats-android with Apache License 2.0 5 votes vote down vote up
public Rating(FirebaseUser user, double rating, String text) {
    this.userId = user.getUid();
    this.userName = user.getDisplayName();
    if (TextUtils.isEmpty(this.userName)) {
        this.userName = user.getEmail();
    }

    this.rating = rating;
    this.text = text;
}
 
Example 10
Source File: Rating.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
public Rating(FirebaseUser user, double rating, String text) {
    this.userId = user.getUid();
    this.userName = user.getDisplayName();
    if (TextUtils.isEmpty(this.userName)) {
        this.userName = user.getEmail();
    }

    this.rating = rating;
    this.text = text;
}
 
Example 11
Source File: LoginActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
private void updateInfo() {
    FirebaseUser user = mAuth.getCurrentUser();
    if (user != null) {
        USER_ID = user.getUid();
        USER_EMAIL = user.getEmail();
        // Picasso.with(ActivityFUIAuth.this).load(user.getPhotoUrl()).into(imgProfile);
    }
}
 
Example 12
Source File: SignInUI.java    From stockita-point-of-sale with MIT License 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {

        case RC_SIGN_IN:

            if (resultCode == RESULT_OK) {
                // user is signed in!

                /**
                 * Get a reference for the current signed in user, and get the
                 * email and the UID
                 */
                FirebaseUser userProfile = FirebaseAuth.getInstance().getCurrentUser();

                if (userProfile != null) {


                    // Get the photo Url
                    Uri photoUri = userProfile.getPhotoUrl();
                    final String photoUrl = photoUri != null ? photoUri.getPath() : null;

                    // Get the user name and store them in SharedPreferences for later use.
                    final String profileName = userProfile.getDisplayName();

                    // Get the user email and store them in SharedPreferences for later use.
                    final String profileEmail = userProfile.getEmail();

                    // Get the user UID and sore them in SharedPreferences for later use.
                    final String profileUid = userProfile.getUid();

                    // Encoded the email that the user just signed in with
                    String encodedUserEmail = Utility.encodeEmail(profileEmail);

                    // Register the current sign in data in SharedPreferences for later use
                    Utility.registerTheCurrentLogin(getBaseContext(), profileName, profileUid, encodedUserEmail, photoUrl);

                    // Initialize the Firebase reference to the /users/<userUid> location
                    final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference()
                            .child(Constants.FIREBASE_USER_LOCATION)
                            .child(profileUid);

                    // Listener for a single value event, only one time this listener will be triggered
                    databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                            // Check if hasChildren means already exists
                            if (!dataSnapshot.hasChildren()) {

                                /**
                                 * Create this new user into /users/ node in Firebase
                                 */
                                Utility.createUser(getBaseContext(), profileName, profileUid, profileEmail, photoUrl);
                            }

                        }

                        @Override
                        public void onCancelled(@NonNull DatabaseError databaseError) {

                            // Get the message in to the logcat
                            Log.e("check if users exist", databaseError.getMessage());
                        }
                    });
                }

                // When signed in then start the main activity
                startActivity(new Intent(this, MainActivity.class));
                finish();

            } else {
                // user is not signed in. Maybe just wait for the user to press
                // "sign in" again, or show a message
                Log.e(TAG_LOG, "not failed to sign in");
            }
    }
}
 
Example 13
Source File: FirestackAuth.java    From react-native-firestack with MIT License 5 votes vote down vote up
private WritableMap getUserMap() {
    WritableMap userMap = Arguments.createMap();

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    if (user != null) {
      final String email = user.getEmail();
      final String uid   = user.getUid();
      final String provider = user.getProviderId();
      final String name = user.getDisplayName();
      final Uri photoUrl = user.getPhotoUrl();

      userMap.putString("email", email);
      userMap.putString("uid", uid);
      userMap.putString("providerId", provider);
      userMap.putBoolean("emailVerified", user.isEmailVerified());
      userMap.putBoolean("anonymous", user.isAnonymous());
      if (name != null) {
        userMap.putString("displayName", name);
      }

      if (photoUrl != null) {
        userMap.putString("photoUrl", photoUrl.toString());
      }
    } else {
      userMap.putString("msg", "no user");
    }

    return userMap;
}
 
Example 14
Source File: AnonymousUpgradeActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private String getUserIdentifier(FirebaseUser user) {
    if (user.isAnonymous()) {
        return user.getUid();
    } else if (!TextUtils.isEmpty(user.getEmail())) {
        return user.getEmail();
    } else if (!TextUtils.isEmpty(user.getPhoneNumber())) {
        return user.getPhoneNumber();
    } else {
        return "unknown";
    }
}
 
Example 15
Source File: AuthModuleImpl.java    From Android-MVP-vs-MVVM-Samples with Apache License 2.0 3 votes vote down vote up
@Override
public final User getUser() {
    final FirebaseUser firebaseUser = firebaseAuthManager.getUser();

    if(firebaseUser == null) return null;

    return new User(firebaseUser.getUid(), firebaseUser.getEmail());

}