I am using Firebase for user authentication through email and password and I want to retrieve the username of a user from authData
but I only see the uid
. I want to retrieve the username so I can display it on another activity.
Here is my code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ref.authWithPassword(email.getText().toString(), password.getText().toString(), new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
setContentView(R.layout.activity_user_display);
Map<String, String> map = new HashMap<String, String>();
map.put("provider", authData.getProvider());
if(authData.getProviderData().containsKey("displayName")){
map.put("displayName", authData.getProviderData().get("displayName").toString());
}
else
{
Context c = getApplicationContext();
Toast t = Toast.makeText(c, "You thought you had it", Toast.LENGTH_SHORT);
}
ref.child("users").child(authData.getUid()).setValue(map);
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
Context c = getApplicationContext();
Toast error = Toast.makeText(c,"Sorry :)",Toast.LENGTH_SHORT);
}
});
}
});`
and the result is this the result from the code above:
Thank you.