skip to Main Content

I am trying to display the Facebook profile image using Glide in an ImageView once the user logs in, the problem is that Glide only loads the default image from Facebook, I have tried different ways but it always loads the same image by default.

This is the image that Glide shows

Here is my code:

onCreate method:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_menu, container, false);

    if (AccessToken.getCurrentAccessToken() == null){
        goLoginScreen();
    }else {
        Profile profile = Profile.getCurrentProfile();
        if (profile != null){
            displayProfileInfo(profile);
        }else{
            Profile.fetchProfileForCurrentAccessToken();
        }
    }
    return view;
}

displayProfileInfo method:

private void displayProfileInfo(Profile profile){
    String name = profile.getName();
    String photoUrl = profile.getProfilePictureUri(100,100).toString();

    txtviewUname.setText(name);
    Glide.with(getActivity()).load(photoUrl).into(profileImage);
}

2

Answers


  1. Use context, for exemple

    getContext()

    or

    requireContext()

    , if it is in Activity use only

    this

    Glide use Context

    Login or Signup to reply.
  2. According to your comment:

    when I put the URL in the browser, it shows me the same image by default.

    This means that the getPhotoUrl() method that exists in the FirebaseUser class, returns an URL that points to a valid photo. However, that photo is added automatically by Facebook when the users decide not to add any photos to the profile. So if a user doesn’t have any photos, the default photo will always be displayed. So when you try to read the photo that is associated to such an account, the default photo will be displayed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search