使用意图显示Google+个人资料照片

时间:2014-01-06 06:25:27

标签: android android-studio google-plus

尝试显示已登录我的应用的用户的个人资料图片。这是一个简单的应用,只需签署某个人,并在成功登录后启动logout活动。在注销活动中,我试图显示欢迎消息和用户的图片。到目前为止,我已经通过在onConnected()中定义MainActivity方法来获得欢迎消息:

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

在我的LogoutActivity课程中我添加了这些行

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

问题是我不知道用profilePicture调用什么方法。我试过了

profilePicture.setImageResource(in.getStringExtra("profile_photo"));但我收到了错误

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

有人可以指出我正确的方向吗?

1 个答案:

答案 0 :(得分:2)

   in.getStringExtra("profile_photo");

您正在收到个人资料图片的网址,因此您应该从该网址下载图片,然后将该图片设置为Imageview。

看看这里:

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/

这应该可以帮助您在获取网址后显示图像