Ojonugwa Jude Ochalifu
Ojonugwa Jude Ochalifu

Reputation: 27256

Displaying Google+ profile picture using intents

Am trying do display the profile picture of a user who has signed in to my app.This is a simple app that just signs someone in, and starts a logout activity upon successful login.In the logout activity, am trying to display a welcome message and the picture of the user.So far I've got the welcome message to work by defining the onConnected() method in the MainActivity as so:

public void onConnected(Bundle connectionHint) {
    String accountName = mPlusClient.getAccountName();
    Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show();
    Intent startLogoutActivityIntent = new Intent(this, LogoutActivity.class);
    startLogoutActivityIntent.putExtra("ACCOUNT_NAME", accountName);

    if (mPlusClient.getCurrentPerson() != null) {
        Person currentPerson = mPlusClient.getCurrentPerson();
        String personName = currentPerson.getDisplayName();
        String photo = currentPerson.getImage().getUrl();
        String personGooglePlusProfile = currentPerson.getUrl();

        startLogoutActivityIntent.putExtra("Profile_photo", photo);
    }

    startActivity(startLogoutActivityIntent);
}

and in my LogoutActivity class i added these lines

TextView message = (TextView) findViewById(R.id.welcomeMessage);
message.setText("Welcome to the DivingScores app " + in.getStringExtra
("ACCOUNT_NAME"));

ImageView profilePicture = (ImageView) findViewById(R.id.userImage);

The problem is i don't know what method to call with profilePicture. I have tried

profilePicture.setImageResource(in.getStringExtra("profile_photo")); but i get the error

setImageResource (int) in ImageView cannot be applied to (java.lang.String).

Can someone please point me in the right direction?

Upvotes: 0

Views: 1062

Answers (1)

Adnan Mulla
Adnan Mulla

Reputation: 2866

   in.getStringExtra("profile_photo");

You are receiving a url to the profile image, so you should download the image from that url and then set that image to the Imageview.

Have a look here :

http://www.androidhive.info/2012/07/android-loading-image-from-url-http/

http://theopentutorials.com/tutorials/android/imageview/android-how-to-load-image-from-url-in-imageview/

That should help you display the image after fetching the url

Upvotes: 2

Related Questions