英文:
How to get display name "email"?
问题
[1]: https://i.stack.imgur.com/AZBMv.png
这张图片显示数据库用户名为空,我想从用户注册/登录的电子邮件中设置用户名。
public void memperbaruiQuest() {
String uid = getUid(); // 这是 FirebaseAuth.getInstance().getCurrentUser().getUid()
final DatabaseReference mScore = mdatabase.child(Aktivitas).child(String.valueOf(uid));
DatabaseReference muser = FirebaseDatabase.getInstance().getReference().child("Users").child(String.valueOf(uid)).child("用户名");
muser.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String name = String.valueOf(dataSnapshot.getValue());
mScore.child("用户名").setValue(name); //这是空的?
在登录后我能获取到电子邮件或用户名吗?
为了在Firebase中用户名不为空,我需要做什么?谢谢
<details>
<summary>英文:</summary>
this image show database username is null, I want to set name from email user registered/logined
public void memperbaruiQuest() {
String uid = getUid(); // this is FirebaseAuth.getInstance().getCurrentUser().getUid()
final DatabaseReference mScore = mdatabase.child(Aktivitas).child(String.valueOf(uid));
DatabaseReference muser = FirebaseDatabase.getInstance().getReference().child("Users").child(String.valueOf(uid)).child("User name");
muser.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String name = String.valueOf(dataSnapshot.getValue());
mScore.child("username").setValue(name); //this is null?
can i get the email or name after login?
what I must doing for the username no null in firebase? thank you
答案1
得分: 0
一旦用户已登录,您可以执行以下操作来获取电子邮件和姓名。
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String name = user.getDisplayName();
String email = user.getEmail();
然后,您可以在您的Firebase数据库中更新这些信息。确保访问正确的节点。
英文:
Once the user is logged in you can do this to get the email and name.
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String name = user.getDisplayName();
String email = user.getEmail();
After, you can update those in your firebase database.Make sure you access the right nodes though.
答案2
得分: 0
Sure, here's the translated code portion:
public void updateQuest() {
String uid = getUid();
final DatabaseReference mScore = mdatabase.child(Activity).child(String.valueOf(uid));
DatabaseReference mUser = FirebaseDatabase.getInstance().getReference(Activity).child(uid);
final String user = FirebaseAuth.getInstance().getCurrentUser().getEmail(); // just add this
mUser.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String.valueOf(dataSnapshot.getValue());
mScore.child("username").setValue(user); // and set it here
}
});
}
And here's the translated comment:
this is a picture I mean hehe
英文:
i solve that ...
public void memperbaruiQuest() {
String uid = getUid();
final DatabaseReference mScore = mdatabase.child(Aktivitas).child(String.valueOf(uid));
DatabaseReference muser = FirebaseDatabase.getInstance().getReference(Aktivitas).child(uid);
final String user = FirebaseAuth.getInstance().getCurrentUser().getEmail(); // just add this
muser.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String.valueOf(dataSnapshot.getValue());
mScore.child("username").setValue(user); //and set on here
}
[1]: https://i.stack.imgur.com/i9LZs.png
this is a picture I mean hehe
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论