Reputation: 98
How can I retrieve a photo of the user? I have successfully get user name and email address, but i don't know how to get user's profile picture and load it into the Image View. How to do that?
I have tried.
auth = FirebaseAuth.getInstance()
val x = auth!!.currentUser!!.photoUrl.toString()
imageView!!.setImageBitmap(BitmapFactory.decodeFile(x))
But it doesn't work
Upvotes: 0
Views: 329
Reputation: 486
It worked for me using Glide. I used java code though.
First, implement Glide module in you gradle app:
// Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
Second, create a class that extends AppGlideModule.
This class registers a FirebaseImageLoader to handle StorageReference.
Don't forget annotations or it won't work.
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
// Register FirebaseImageLoader to handle StorageReference
registry.append(StorageReference.class, InputStream.class,
new FirebaseImageLoader.Factory());
}
}
Third, load the image in your image view
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference yourPicRererence = storage.getReference().child("Path to your picture");
GlideApp.with(getContext()) /* your context */
.load(yourPicRererence) /* your picture*/
.centerCrop() /* this is optional */
.into(imageView); /* your image view*/
(Source: https://github.com/firebase/FirebaseUI-Android/tree/master/storage)
Upvotes: 1