How do I retrieve the name and email of the logged-in user? It is giving code error. I am using BD Firebase.
public class MenuActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private Toolbar toolbar;
private TextView nomePefil, emailPerfil;
private FirebaseAuth autenticacao;
private DatabaseReference firebase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//Recuperar Nome e E-mail para o Menu
nomePefil = findViewById(R.id.tv_nomePerfil);
emailPerfil = findViewById(R.id.tv_emailPerfil);
autenticacao = FirebaseAuth.getInstance();
String email = autenticacao.getCurrentUser().getEmail();
//>>>>>>>> erro aqui <<<<<<<<<<
emailPerfil.setText(email);
firebase = FirebaseDatabase.getInstance().getReference();
firebase.child("usuarios").orderByChild("email").equalTo(email).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapShot : dataSnapshot.getChildren()){
String nome = postSnapShot.child("nome").getValue().toString();
nomePefil.setText(nome);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}