Java Code Examples for com.google.firebase.auth.FirebaseUser#getPhotoUrl()
The following examples show how to use
com.google.firebase.auth.FirebaseUser#getPhotoUrl() .
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 |
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 custom-auth-samples with Apache License 2.0 | 7 votes |
/** * Update UI based on Firebase's current user. Show Login Button if not logged in. */ private void updateUI() { FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser(); if (currentUser != null) { binding.setCurrentUser(currentUser); if (currentUser.getPhotoUrl() != null) { Glide.with(this) .load(currentUser.getPhotoUrl()) .into(imageView); } loginButton.setVisibility(View.INVISIBLE); loggedInView.setVisibility(View.VISIBLE); logoutButton.setVisibility(View.VISIBLE); } else { loginButton.setVisibility(View.VISIBLE); loggedInView.setVisibility(View.INVISIBLE); logoutButton.setVisibility(View.INVISIBLE); } }
Example 3
Source File: MainActivity.java From protrip with MIT License | 7 votes |
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 4
Source File: ProfileActivity.java From friendlypix-android with Apache License 2.0 | 6 votes |
private void showSignedInUI(FirebaseUser firebaseUser) { Log.d(TAG, "Showing signed in UI"); mSignInUi.setVisibility(View.GONE); mProfileUi.setVisibility(View.VISIBLE); mProfileUsername.setVisibility(View.VISIBLE); mProfilePhoto.setVisibility(View.VISIBLE); if (firebaseUser.getDisplayName() != null) { mProfileUsername.setText(firebaseUser.getDisplayName()); } if (firebaseUser.getPhotoUrl() != null) { GlideUtil.loadProfileIcon(firebaseUser.getPhotoUrl().toString(), mProfilePhoto); } Map<String, Object> updateValues = new HashMap<>(); updateValues.put("displayName", firebaseUser.getDisplayName() != null ? firebaseUser.getDisplayName() : "Anonymous"); updateValues.put("photoUrl", firebaseUser.getPhotoUrl() != null ? firebaseUser.getPhotoUrl().toString() : null); FirebaseUtil.getPeopleRef().child(firebaseUser.getUid()).updateChildren( updateValues, new DatabaseReference.CompletionListener() { @Override public void onComplete(DatabaseError firebaseError, DatabaseReference databaseReference) { if (firebaseError != null) { Toast.makeText(ProfileActivity.this, "Couldn't save user data: " + firebaseError.getMessage(), Toast.LENGTH_LONG).show(); } } }); }
Example 5
Source File: MainActivity.java From custom-auth-samples with Apache License 2.0 | 6 votes |
private void updateUI() { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user == null) { mLineLoginButton.setVisibility(View.VISIBLE); mLoggedInView.setVisibility(View.INVISIBLE); } else { Log.d(TAG, "UID = " + user.getUid()); Log.d(TAG, "Provider ID = " + user.getProviderId()); mLineLoginButton.setVisibility(View.INVISIBLE); mLoggedInView.setVisibility(View.VISIBLE); mDisplayNameText.setText(user.getDisplayName()); if (user.getPhotoUrl() != null) { mProfileImageView.setImageUrl(user.getPhotoUrl().toString(), mImageLoader); } } }
Example 6
Source File: PlaceDetailActivity.java From protrip with MIT License | 6 votes |
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 7
Source File: UserModel.java From openwebnet-android with MIT License | 6 votes |
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: MainActivity.java From white-label-event-app with Apache License 2.0 | 6 votes |
@Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { final FirebaseUser user = firebaseAuth.getCurrentUser(); if (user != null) { LOGGER.fine("onAuthStateChanged: " + user.getUid()); navigationHeaderView.showViewId(R.id.vg_profile); final TextView tv_name = (TextView) navigationHeaderView.findViewById(R.id.tv_name); final String name = user.getDisplayName(); tv_name.setText(name != null ? name : "[No name]"); final Uri photoUrl = user.getPhotoUrl(); Glide .with(MainActivity.this) .load(photoUrl) .centerCrop() .placeholder(R.drawable.nopic) .into((ImageView) navigationHeaderView.findViewById(R.id.iv_pic)); if (state.isRequestingSignin) { Toast.makeText( MainActivity.this, getString(R.string.msg_sign_in_thank_you, user.getDisplayName()), Toast.LENGTH_SHORT).show(); state.isRequestingSignin = false; } } else { LOGGER.fine("onAuthStateChanged: signed out"); navigationHeaderView.showViewId(R.id.button_sign_in); ((TextView) navigationHeaderView.findViewById(R.id.tv_name)).setText(null); ((ImageView) navigationHeaderView.findViewById(R.id.iv_pic)).setImageBitmap(null); } }
Example 9
Source File: CredentialUtils.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
/** * 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 10
Source File: SignInUI.java From stockita-point-of-sale with MIT License | 5 votes |
@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 11
Source File: FirestackAuth.java From react-native-firestack with MIT License | 5 votes |
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 12
Source File: SignedInActivity.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
private void populateProfile(@Nullable IdpResponse response) { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user.getPhotoUrl() != null) { GlideApp.with(this) .load(user.getPhotoUrl()) .fitCenter() .into(mUserProfilePicture); } mUserEmail.setText( TextUtils.isEmpty(user.getEmail()) ? "No email" : user.getEmail()); mUserPhoneNumber.setText( TextUtils.isEmpty(user.getPhoneNumber()) ? "No phone number" : user.getPhoneNumber()); mUserDisplayName.setText( TextUtils.isEmpty(user.getDisplayName()) ? "No display name" : user.getDisplayName()); if (response == null) { mIsNewUser.setVisibility(View.GONE); } else { mIsNewUser.setVisibility(View.VISIBLE); mIsNewUser.setText(response.isNewUser() ? "New user" : "Existing user"); } List<String> providers = new ArrayList<>(); if (user.getProviderData().isEmpty()) { providers.add(getString(R.string.providers_anonymous)); } else { for (UserInfo info : user.getProviderData()) { switch (info.getProviderId()) { case GoogleAuthProvider.PROVIDER_ID: providers.add(getString(R.string.providers_google)); break; case FacebookAuthProvider.PROVIDER_ID: providers.add(getString(R.string.providers_facebook)); break; case TwitterAuthProvider.PROVIDER_ID: providers.add(getString(R.string.providers_twitter)); break; case EmailAuthProvider.PROVIDER_ID: providers.add(getString(R.string.providers_email)); break; case PhoneAuthProvider.PROVIDER_ID: providers.add(getString(R.string.providers_phone)); break; case EMAIL_LINK_PROVIDER: providers.add(getString(R.string.providers_email_link)); break; case FirebaseAuthProvider.PROVIDER_ID: // Ignore this provider, it's not very meaningful break; default: providers.add(info.getProviderId()); } } } mEnabledProviders.setText(getString(R.string.used_providers, providers)); }