Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Implementing Designs for Android Customizing a GridView for Friends Retrieving Gravatar Images

Bojie Jiang
PLUS
Bojie Jiang
Courses Plus Student 8,221 Points

Gravatar are not showing up in android app

After using following code,

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);
        }

The Gravatar are still not showing up in android app

Hi Bojie,

I am guessing that 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 "SDFSDSF@DSFSsdfsFSFSssf.com"

That friend will have an gravatar cartoon image.

Bojie Jiang
Bojie Jiang
Courses Plus Student 8,221 Points

Hi, haunguyen,

Thanks so much for your reply. It works, my friends have an gravatar cartoon image.

But, I add my email, which have a portrait image, but it still can not show in my friend list.

Do you know how to fix it? Thanks again.

So now you know that the Picasso part of the code works.

Why don't you use the Log.d("GRAVATAR URL", "http://www.gravatar.com/avatar/" + hash ); to get the gravatar URLs, and paste those urls into the browser address bar to see if gravatar actually returns back your expected images.

If you don't get your images, you might want to log the returned emails to see if they are the correct emails. You might also want to use the trim function to trim extra spaces from the emails.

Bojie Jiang
Bojie Jiang
Courses Plus Student 8,221 Points

Hi haunguyen,

Thanks for reply. I did Log things, and checked the email, but still no luck. I use gmail, which has changed profile photo. It seems that GRAVATAR cannot get it.

BTW, my gmail is jiangbojie@gmail.com, you can check if you want. Thank you so much!

Your email does not have an gravatar image as of now.

Why don't you try pasting this link (after removing the return character) and see if you see the image (it is the image of team treehouse's CEO). It works for me.

http://www.gravatar.com/avatar/

edb1260aa6f7f77688deee83e0a088f7?s=204&d=monsterid

Bojie Jiang
Bojie Jiang
Courses Plus Student 8,221 Points

Yeah, I saw CEO, lol.

I am wondering how my gmail get gravatar image? It's not simply change the profile picture? or I need to set my gravatar image on the gravatar website?

I don't use gravatar, so I don't know how they get images. But gravatar is for demo purpose only, the important part of this lesson is how to use the picasso library to import images from the web into the imageview. You could also try to have users uploading their own profile images.

1 Answer

aimensasi
aimensasi
11,343 Points

you need to link your email to gravatar https://en.gravatar.com/ and set the image