androidgoogle-plus

Displaying Google Plus user profile picture in Android app


Am trying to display the profile picture of users logged into my app through Google+ but am not sure how to do this.To get the image (and other information), google provides the code

@Override
public void onConnected() {
...
if (mPlusClient.getCurrentPerson() != null) {
    Person currentPerson = mPlusClient.getCurrentPerson();
    String personName = currentPerson.getDisplayName();
    String personPhoto = currentPerson.getImage();
    String personGooglePlusProfile = currentPerson.getUrl();
}
}

I am aware that ordinarily i would need to get any image i want to display from res/drawable... but i don't know what to do with the value of personPhoto (which somehow get's changed from type String to Image when you paste the code in Eclipse.


Solution

  • You need to use that URL to grab the photo as a bitmap and set it to an imageview.

    Section 4.9 of this article explains how to make an asynctask that will do just that:

    http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/