2014-02-11 88 views
3

我試圖顯示通過Google+登錄到我的應用的用戶的個人資料圖片,但我不知道如何做到這一點。要獲取圖片(和其他信息),谷歌提供的代碼在Android應用中顯示谷歌加用戶個人資料圖片

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

我知道,通常我需要得到我想從res/drawable...顯示任何圖像,但我不知道做什麼用的personPhoto值做(這在某種程度上得到的來自String類型更改爲Image時您將代碼粘貼到Eclipse中。

+0

有是Google Play服務中的輔助程序類,用於加載從其返回的圖像:http://developer.android.com/reference/com/google/android/gms/common/images/ImageManager.html –

回答

0

首先,你需要添加在你的應用程序/文件的build.gradle這種依賴性:

dependencies {compile 'com.github.bumptech.glide:glide:3.8.0'} 

此更新您的UI因此後:

private void updateUI(GoogleSignInAccount account) { 
    if (account != null){ 
     text.setText("Sign in as :" +account.getDisplayName()); 
     email.setText(account.getEmail()); 
     String imgurl = account.getPhotoUrl().toString(); 
     Glide.with(this).load(imgurl).into(profile); 
     sighIn.setVisibility(View.GONE); 
     sighOut.setVisibility(View.VISIBLE); 
    } 
    else { 
     text.setText("signOut"); 
     sighIn.setVisibility(View.VISIBLE); 
     sighOut.setVisibility(View.GONE); 
    } 
} 
相關問題