Android – how to add a user’s name, profile, picture and address to the firebase database?
I'm trying to create an android app. I want to save each user's personal details (such as name, profile, photo and address) to the firebase database for future use
What do you suggest I do?
resolvent:
You haven't taken the time to get familiar with these firebase docs. That's why there are so many low votes for your questions. I'd also like to briefly introduce what firebase provides you:
//This is how you get the user profile data for each logged in user
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();
// 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.getToken() instead.
String uid = user.getUid();
}
//This is how you update the user profile data for each logged in user
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName("Jane Q. User")
.setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
.build();
user.updateProfile(profileUpdates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User profile updated.");
}
}
});
If you use firebase without implementing any authentication and security rules, I would say you should change it as soon as possible. Because there are no authentication and appropriate security rules, anyone can access your database and change it in any way he / she wants
For logged in users, you do not need to perform any additional or special operations to save their profile details. If you use authentication providers such as Gmail and Facebook, firebase will automatically save basic profile information. If you use some custom authentication methods, Please refer to the code snippet for updating user profile provided by firebase. This is how you save the basic user profile
If it helps you, please let me know