[英]Can't get user name and email in firebase
When I Sign in with Firebase after writing Name, last name and take profile picture, I press "Finish Registration" and starts activity of user account and the name of user and profile picture not showing besides user email address.当我在输入姓名、姓氏并拍摄个人资料图片后使用 Firebase 登录时,我按“完成注册”并启动用户帐户的活动,除了用户电子邮件地址外,用户名称和个人资料图片未显示。 But when I restart my application user name and profile picture is showing.
但是当我重新启动我的应用程序用户名和个人资料图片时显示。 I want to show name and profile picture after registering user data(name, last name, profile picture).
我想在注册用户数据(姓名、姓氏、个人资料图片)后显示姓名和个人资料图片。 How can I solve it ?
我该如何解决?
Registering User Data Activity code注册用户数据活动代码
finishRegistration.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final ProgressDialog loadData = ProgressDialog.show(RegisterUserInformation.this,"Sending data to Server", "Please wait", true,false);
UserProfileChangeRequest request = new UserProfileChangeRequest.Builder()
.setDisplayName("" + name.getText().toString() + " " + lastname.getText().toString()).build();
mUser.updateProfile(request);
mStorageReference.child("Online Scheduler").child("Users").child("" + mUser.getUid()).child("Profile Picture").putFile(selectedImage)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
loadData.dismiss();
}
});
HashMap<String, Object> userData = new HashMap<>();
userData.put("Name", name.getText().toString());
userData.put("Last name", lastname.getText().toString());
userData.put("Email", mUser.getEmail());
userData.put("UId", mUser.getUid());
myRef.child("Online Scheduler").child("Users").child("" + mUser.getUid()).child("User Information").setValue(userData).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
loadData.dismiss();
Intent goToUserAccount = new Intent(getApplicationContext(),Account.class);
startActivity(goToUserAccount);
}
});
}
});
User Account Activity code用户帐户活动代码
if(mUser != null)
{
name.setText(mUser.getDisplayName());
email.setText(mUser.getEmail());
Log.d(logTag,"" + mUser.getDisplayName());
Log.d(logTag, "" + mUser.getEmail());
//Get profile picture for facebook authentication user.
Glide.with(getApplicationContext()).load(mUser.getPhotoUrl()).listener(new RequestListener<Uri, GlideDrawable>() {
@Override
public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {
progressBar.setVisibility(View.INVISIBLE);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
progressBar.setVisibility(View.INVISIBLE);
return false;
}
}).into(avatar); // Get profile picture for facebook authentication user.
//Get profile picture for email authentication user.
sRef.child("Online Scheduler").child("Users").child("" + mUser.getUid()).child("Profile Picture")
.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(final Uri uri) {
Glide.with(getApplicationContext()).load(uri).listener(new RequestListener<Uri, GlideDrawable>() {
@Override
public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {
Log.d(logTag,"" + uri.toString());
progressBar.setVisibility(View.INVISIBLE);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
Log.d(logTag,"" + uri.toString());
progressBar.setVisibility(View.INVISIBLE);
return false;
}
}).into(avatar);
}
}); //Get profile picture for email authentication user.
}
You need to add some EventListener to the firesdatabase so that you will listen to the changes;您需要向 firesdatabase 添加一些 EventListener 以便您可以监听更改; The onDataChange callback method will be called whenever you change firebasedatabase.
每当您更改 firebasedatabase 时,都会调用 onDataChange 回调方法。 Example;
例子; EventListener, ChildEventListener, ValueEventListener
事件监听器、子事件监听器、值事件监听器
mStorageReference.child("Online
Scheduler").child("Users").child("Uid")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
}
@Override
public void onCancelled(DatabaseError databaseError)
}
});
https://firebase.google.com/docs/database/android/read-and-write#listen_for_value_events https://firebase.google.com/docs/database/android/lists-of-data#child-events https://firebase.google.com/docs/database/android/lists-of-data#listen_for_value_events https://firebase.google.com/docs/database/android/read-and-write#listen_for_value_events https://firebase.google.com/docs/database/android/lists-of-data#child-events https: //firebase.google.com/docs/database/android/lists-of-data#listen_for_value_events
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.