How to show the connected user’s Firebase ID on the screen?

Asked

Viewed 360 times

0

I need to take getUid from the connected user and set the id in an editText. I left it down just to show what I want to do, because that way it doesn’t work. How can I call a getUid connected to any part of the code and set it as Edittext?

private EditText userId;
private FirebaseAuth.AuthStateListener minhaAuthListener;

userId = (EditText)findViewById(R.id.userId);


 minhaAuthListener = new FirebaseAuth.AuthStateListener(){
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            Log.d("meuLog", "Usuário conectado: " + user.getUid());
            userId.setText(user.getUid());
        }
    };

1 answer

0

I was able to solve it this way.

    FirebaseUser user1 = FirebaseAuth.getInstance().getCurrentUser();
    if (user1 != null) {
        for (UserInfo profile : user1.getProviderData()) {
            // Id of the provider (ex: google.com)
            String providerId = profile.getProviderId();
            // UID specific to the provider
            String uid = user1.getUid();
            userId.setText(uid);
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.