如何将用户默认个人资料图片(使用google进行身份验证)放入firebase存储?
private StorageReference stRef;
private DatabaseReference userDb;
private FirebaseAuth mAuth;
Users users1 = new Users(mAuth.getCurrentUser().getDisplayName(),mAuth.getCurrentUser().getEmail()
,mAuth.getCurrentUser().getUid(),
new SimpleDateFormat("yyyy-MM-dd").format(new Date()),studyDetails,mAuth.getCurrentUser().getPhotoUrl());
userDb.child(mAuth.getCurrentUser().getUid()).setValue(users1);
这未能存储在数据库中
答案 0 :(得分:1)
您可以使用以下方式访问用户图片:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
Uri photoUrl = user.getPhotoUrl();
}
Here the auth user documentation.
设置用户图片:
mDatabase.child("users").child(userId).child("photoUrl").setValue(photoUrl);
检索其他用户图片:
mDatabase.child("users").child(userId).child("photoUrl").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String photoUrl = (String) dataSnapshot.getValue();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
答案 1 :(得分:0)
//while storing user details
Users users1 = new Users(
mAuth.getCurrentUser().getDisplayName(),
mAuth.getCurrentUser().getEmail(),
mAuth.getCurrentUser().getUid(),
new SimpleDateFormat("yyyy-MM-dd").format(new Date()), studyDetails, mAuth.getCurrentUser().getPhotoUrl().toString()
);
userDb.child(mAuth.getCurrentUser().getUid()).setValue(users1);
//While Retriving user datials
holder.txtName.setText(users.getsUserName());
holder.txtEmial.setText(users.getsEmailId());
holder.txtJoined.setText("Joined on: " + users.getsDateJoined());
Uri uri = Uri.parse(users.getPhotoUri());
Picasso.with(context)
.load(uri)
.transform(new CircleTransform())
.resize(150, 150)
.centerCrop()
.into(holder.imageView);