ojo*_*ifu 4 android google-plus
我试图通过Google+显示登录到我的应用的用户的个人资料图片,但我不知道如何执行此操作.要获取图像(和其他信息),Google会提供代码
@Override
public void onConnected() {
...
if (mPlusClient.getCurrentPerson() != null) {
Person currentPerson = mPlusClient.getCurrentPerson();
String personName = currentPerson.getDisplayName();
String personPhoto = currentPerson.getImage();
String personGooglePlusProfile = currentPerson.getUrl();
}
}
Run Code Online (Sandbox Code Playgroud)
我知道,通常我需要得到我想从显示任何图像res/drawable...,但我不知道做什么用的价值做personPhoto(这在某种程度上得到的改变,从类型String到Image当粘贴在Eclipse中的代码.
您需要使用该URL来将照片捕获为位图并将其设置为imageview。
本文的第4.9节说明了如何制作一个异步任务来完成该任务:
http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/
小智 5
首先,您需要在app/build.gradle文件中添加此依赖项:
dependencies {compile 'com.github.bumptech.glide:glide:3.8.0'}
Run Code Online (Sandbox Code Playgroud)
在此更新后,您的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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16106 次 |
| 最近记录: |