[英]how to get photo url of email account user signed into android app through FirebaseAuth with Email signIn
I used Firebase Authentication with only Email/Password in an android app project. 我在Android应用程序项目中仅对电子邮件/密码使用了Firebase身份验证。 I tried to access the picture of the email account which has been used to log into the app.
我试图访问已用于登录应用程序的电子邮件帐户的图片。 However, the photoUrl is null when I try these three methods below and I am testing with my own email account which I know has a profile picture.
但是,当我尝试以下三种方法时,photoUrl为空,并且正在使用自己的电子邮件帐户进行测试,我知道该帐户具有个人资料图片。
// METHOD ONE
Uri photoUrl = mFirebaseUser.getPhotoUrl();
if (photoUrl != null) {
log.d("PhotoUrl",photoUrl.toString());
}
// METHOD TWO
UserInfo userInfo = mFirebaseUser.getProviderData().get(0);
Uri photoUrl = (Uri) userInfo.getPhotoUrl();
if (photoUrl != null) {
log.d("PhotoUrl",photoUrl.toString());
}
// METHOD THREE
for (UserInfo userInfo:mUser.getProviderData()) {
Uri photoUrl = userInfo1.getPhotoUrl();
if (photoUrl != null){
break;
}
}
if (photoUrl != null) {
log.d("PhotoUrl",photoUrl.toString());
}
I am able to get the name of the email account easily like this 我可以像这样轻松获得电子邮件帐户的名称
String name = mFirebaseUser.getDisplayName();
Try This 尝试这个
private FirebaseAuth mAuth;
private FirebaseUser mCurrentUser;
Initialize it 初始化
mAuth = FirebaseAuth.getInstance();
mCurrentUser = mAuth.getCurrentUser();
Load the Photo Url Using Picasso in Your ImageView 在您的ImageView中使用Picasso加载照片网址
Picasso.get().load(mCurrentUser.getPhotoUrl())
.into(imageView);
As you are using Email sign in only in FirebaseAuth, so the problem happens when you try to retrieve the photo url of the user because there is no photo url for the user by default. 由于仅在FirebaseAuth中使用电子邮件登录,因此当您尝试检索用户的照片url时会发生问题,因为默认情况下该用户没有照片url。 So what you can do is you can ask user to set the photo and save the url with the FirebaseAuth (so that you can retrieve later).
因此,您可以要求用户设置照片并使用FirebaseAuth保存网址(以便以后可以检索)。 You can use the code below to save the photo url for the user.
您可以使用以下代码为用户保存照片网址。
UserProfileChangeRequest userProfileChangeRequest = new UserProfileChangeRequest.Builder() .setDisplayName("set new display name") .setPhotoUri(uri) .build(); FirebaseAuth.getInstance().getCurrentUser().updateProfile(userProfileChangeRequest);
after setting the photo url. 设置照片网址后。 Try getting the photo url
尝试获取照片网址
FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl();
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.