How do I show the logged-on user's Firebase ID?

0

I need to get the getUid of the connected user and set the id in an editText. I left below just to show what I want to do, because that way it does not work. How can I call a getUid connected in any part of the code and set it to 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());
        }
    };
    
asked by anonymous 09.11.2017 / 23:37

1 answer

0

I was able to resolve it as follows.

    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);
        }
    }
    
10.11.2017 / 00:02