Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java “如何获取显示名称”;电子邮件;?_Java_Android_Firebase_Firebase Realtime Database_Firebase Authentication - Fatal编程技术网

Java “如何获取显示名称”;电子邮件;?

Java “如何获取显示名称”;电子邮件;?,java,android,firebase,firebase-realtime-database,firebase-authentication,Java,Android,Firebase,Firebase Realtime Database,Firebase Authentication,登录后我可以获得电子邮件或姓名吗? 对于firebase中的用户名no null,我必须做什么?多谢各位 public void memperbaruiQuest() { String uid = getUid(); // this is FirebaseAuth.getInstance().getCurrentUser().getUid() final DatabaseReference mScore = mdatabase.child(Aktivitas

登录后我可以获得电子邮件或姓名吗? 对于firebase中的用户名no null,我必须做什么?多谢各位

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?




用户登录后,您可以通过此操作获取电子邮件和姓名

  
之后,您可以更新firebase数据库中的节点。但请确保您访问了正确的节点。

我解决了这个问题

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String name = user.getDisplayName();
String email = user.getEmail();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String name = user.getDisplayName();
String email = user.getEmail();
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