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

The following examples show how to use com.google.firebase.auth.FirebaseUser#getUid() . 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: ProfileInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public void updateRegistrationToken(final String token) {
    FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
    if (firebaseUser != null) {
        final String currentUserId = firebaseUser.getUid();

        getProfileSingleValue(currentUserId, new OnObjectChangedListenerSimple<Profile>() {
            @Override
            public void onObjectChanged(Profile obj) {
                if(obj != null) {
                    addRegistrationToken(token, currentUserId);
                } else {
                    LogUtil.logError(TAG, "updateRegistrationToken",
                            new RuntimeException("Profile is not found"));
                }
            }
        });
    }
}
 
Example 4
Source File: MainActivity.java    From Simple-Blog-App with MIT License 6 votes vote down vote up
private void checkUserExist() {

        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        if (user != null) {
            final String user_id = user.getUid();
            mDatabaseUsers.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if (!dataSnapshot.hasChild(user_id)) {
                        Intent setupIntent = new Intent(MainActivity.this, SetupActivity.class);
                        setupIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(setupIntent);
                    } else {
                        onStart();
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                }
            });
        }
    }
 
Example 5
Source File: ProfileInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public void updateRegistrationToken(final String token) {
    FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
    if (firebaseUser != null) {
        final String currentUserId = firebaseUser.getUid();

        getProfileSingleValue(currentUserId, new OnObjectChangedListenerSimple<Profile>() {
            @Override
            public void onObjectChanged(Profile obj) {
                if(obj != null) {
                    addRegistrationToken(token, currentUserId);
                } else {
                    LogUtil.logError(TAG, "updateRegistrationToken",
                            new RuntimeException("Profile is not found"));
                }
            }
        });
    }
}
 
Example 6
Source File: LoginActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void initializeUserInfo() {
    FirebaseUser user = mAuth.getCurrentUser();
    String userId = user.getUid();

    DatabaseReference usersRef = mDatabase.child("Users");
    DatabaseReference stepsRef = mDatabase.child("Steps");
    DatabaseReference caloriesRef = mDatabase.child("Calories");

    User newUser = new User("", "", "", 0, "", 0, 0, 0);
    usersRef.child(userId).setValue(newUser);

    Steps steps = new Steps(0);
    stepsRef.child(userId).setValue(steps);

    Calories calories = new Calories(0, 0, 0, 0);
    caloriesRef.child(userId).setValue(calories);
}
 
Example 7
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 8
Source File: ProfileInteractor.java    From CourierApplication with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Get logged user data from DB, called from the profilePresenter which is called
 * from the ProfileFragment onViewCreated.
 * Returns user data to the presenter.
 */
public void getUserDataFromDb() {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    final String uid = user.getUid();
    mUser = new User();
    mDatabaseReference.child("users").child(uid).addListenerForSingleValueEvent(
            new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if(dataSnapshot.exists()) {
                        mUser.setName(String.valueOf(dataSnapshot.child("name").getValue()));
                        mUser.setPhone(String.valueOf(dataSnapshot.child("phone").getValue()));
                        mUser.setEmail(String.valueOf(dataSnapshot.child("email").getValue()));
                        mUser.setUid(uid);
                        mUser.setRole(String.valueOf(dataSnapshot.child("role").getValue()));
                        checkAndSetCurrentUserToken(uid);
                        mPresenter.onReceivedUserDataFromDb(mUser);
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            }
    );
}
 
Example 9
Source File: firebaseutils.java    From LuxVilla with Apache License 2.0 5 votes vote down vote up
public static void removelike(String id){
    String uid="";
    FirebaseAuth auth=FirebaseAuth.getInstance();
    FirebaseUser user=auth.getCurrentUser();
    if (user != null){
        uid=user.getUid();
    }
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("users").child(uid).child("likes");
    myRef.child("heart"+id).removeValue();
}
 
Example 10
Source File: ProfileManager.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public Profile buildProfile(FirebaseUser firebaseUser, String largeAvatarURL) {
    Profile profile = new Profile(firebaseUser.getUid());
    profile.setEmail(firebaseUser.getEmail());
    profile.setUsername(firebaseUser.getDisplayName());
    profile.setPhotoUrl(largeAvatarURL != null ? largeAvatarURL : firebaseUser.getPhotoUrl().toString());
    return profile;
}
 
Example 11
Source File: ProfileActivity.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    actionBar = getSupportActionBar();

    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    userID = getIntent().getStringExtra(USER_ID_EXTRA_KEY);

    mAuth = FirebaseAuth.getInstance();
    FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
    if (firebaseUser != null) {
        currentUserId = firebaseUser.getUid();
    }

    // Set up the login form.
    progressBar = findViewById(R.id.progressBar);
    imageView = findViewById(R.id.imageView);
    nameEditText = findViewById(R.id.nameEditText);
    postsCounterTextView = findViewById(R.id.postsCounterTextView);
    likesCountersTextView = findViewById(R.id.likesCountersTextView);
    followersCounterTextView = findViewById(R.id.followersCounterTextView);
    followingsCounterTextView = findViewById(R.id.followingsCounterTextView);
    postsProgressBar = findViewById(R.id.postsProgressBar);
    followButton = findViewById(R.id.followButton);
    swipeContainer = findViewById(R.id.swipeContainer);

    initListeners();

    presenter.checkFollowState(userID);

    loadPostsList();
    supportPostponeEnterTransition();
}
 
Example 12
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 13
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 14
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 15
Source File: ProfileManager.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public Profile buildProfile(FirebaseUser firebaseUser, String largeAvatarURL) {
    Profile profile = new Profile(firebaseUser.getUid());
    profile.setEmail(firebaseUser.getEmail());
    profile.setUsername(firebaseUser.getDisplayName());
    profile.setPhotoUrl(largeAvatarURL != null ? largeAvatarURL : firebaseUser.getPhotoUrl().toString());
    return profile;
}
 
Example 16
Source File: ProfileActivity.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    actionBar = getSupportActionBar();

    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    userID = getIntent().getStringExtra(USER_ID_EXTRA_KEY);

    mAuth = FirebaseAuth.getInstance();
    FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
    if (firebaseUser != null) {
        currentUserId = firebaseUser.getUid();
    }

    // Set up the login form.
    progressBar = findViewById(R.id.progressBar);
    imageView = findViewById(R.id.imageView);
    nameEditText = findViewById(R.id.nameEditText);
    postsCounterTextView = findViewById(R.id.postsCounterTextView);
    likesCountersTextView = findViewById(R.id.likesCountersTextView);
    followersCounterTextView = findViewById(R.id.followersCounterTextView);
    followingsCounterTextView = findViewById(R.id.followingsCounterTextView);
    postsProgressBar = findViewById(R.id.postsProgressBar);
    followButton = findViewById(R.id.followButton);
    swipeContainer = findViewById(R.id.swipeContainer);

    initListeners();

    presenter.checkFollowState(userID);

    loadPostsList();
    supportPostponeEnterTransition();
}
 
Example 17
Source File: FirebaseHelpers.java    From cannonball-android with Apache License 2.0 5 votes vote down vote up
public static String getUserId() {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    if (user == null) {
        return null;
    } else {
        return user.getUid();
    }
}
 
Example 18
Source File: Food_MyRecyclerViewAdapter.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private DatabaseReference getCaloriesRef(String ref) {
    FirebaseUser user = mAuth.getCurrentUser();
    String userId = user.getUid();
    return mDatabase.child("Calories").child(userId).child(ref);
}
 
Example 19
Source File: Food_RecyclerFrag_Main.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private DatabaseReference getCaloriesRef(String ref) {
    FirebaseUser user = mAuth.getCurrentUser();
    String userId = user.getUid();
    return mDatabase.child("Calories").child(userId).child(ref);
}
 
Example 20
Source File: BasicInfoFragment.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private DatabaseReference getUsersRef(String ref) {
    FirebaseUser user = mAuth.getCurrentUser();
    String userId = user.getUid();
    return mDatabase.child("Users").child(userId).child(ref);
}