我目前正在使用android studio开发应用程序,目前使用Firebase用户身份验证进行工作登录。但是,当用户使用此身份验证后登录时,我试图在屏幕上显示图像。我希望将此图像链接到该特定用户。这可能吗?
答案 0 :(得分:1)
您可以使用以下代码在用户的firebase配置文件中设置照片网址:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName("Jane Q. User")
.setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
.build();
user.updateProfile(profileUpdates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User profile updated.");
}
}
});
然后您将检索用户的个人资料信息(包括他们的照片网址),如下所示:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
// Name, email address, and profile photo Url
String name = user.getDisplayName();
String email = user.getEmail();
Uri photoUrl = user.getPhotoUrl();
// Check if user's email is verified
boolean emailVerified = user.isEmailVerified();
// The user's ID, unique to the Firebase project. Do NOT use this value to
// authenticate with your backend server, if you have one. Use
// FirebaseUser.getToken() instead.
String uid = user.getUid();
}
更多信息:https://firebase.google.com/docs/auth/android/manage-users
如果您正在使用oAuth身份验证并想要从Facebook检索他们的个人资料照片,您可以在以下链接中找到有关如何执行此操作的更多信息:
https://firebase.google.com/docs/auth/android/facebook-login