如何获取显示名称 “email”?

huangapple go评论78阅读模式
英文:

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(&quot;Users&quot;).child(String.valueOf(uid)).child(&quot;User name&quot;);
    muser.addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            String name = String.valueOf(dataSnapshot.getValue());

            mScore.child(&quot;username&quot;).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(&quot;username&quot;).setValue(user); //and set on here

        }

  [1]: https://i.stack.imgur.com/i9LZs.png

this is a picture I mean hehe 

huangapple
  • 本文由 发表于 2020年8月31日 17:43:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63668432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定