Gravatar are not showing up in android app

877 Views Asked by At

Here is my code to display profile picture using gravatar.

ParseUser user = mUsers.get(position);
String email = user.getEmail().toLowerCase();

if (email.equals("")) {
    holder.userImageView.setImageResource(R.drawable.avatar_empty);
} else {
    String hash = MD5Util.md5Hex(email);
    String gravatarUrl = "http://www.gravatar.com/avatar/" + hash + "?s=204&d=404";
    Picasso.with(mContext).load(gravatarUrl)
            .placeholder(R.drawable.avatar_empty)
            .into(holder.userImageView);
}

But it is not showing even my profile picture and loads empty drawable.

2

There are 2 best solutions below

2
On BEST ANSWER

You used a bunch of fake emails to populate your friend list, if so, gravatar won't be able to find images for those fake emails. So gravatar will return a 404, and your code will use the default "avatar_empty" image in the drawable folder.

A quick way to test to see if gravatar is working is to change the &d=404 to &d=monsterid and create a friend with a fake email "[email protected]"

That friend will have an gravatar cartoon image.

Also you can try put http://www.gravatar.com/avatar/edb1260aa6f7f77688deee83e0a088f7?s=204&d=monsterid in your gravatarUrl. It will show picture.

0
On

Hope this helps someone , this is the code i used.
get library from:- https://github.com/tkeunebr/gravatar-android (you will get the .jar,, add it to lib)

Code for loading gravatar:

String gravatarUrl = Gravatar.init().with(user.email).size(100).build();
Picasso.with(mContext)
       .load(gravatarUrl)
       .into((ImageView) convertView.findViewById(R.id.user_avatar));

And if you want to set a default image in case of there is no gravatar set for the email(to override the default gravatar) then use:

String gravatarUrl = Gravatar.init().with(user.email).defaultImage(defaultImageUrl).size(100).build();

Hope this helps someone.