假设用户已在手机上登录其Google+帐户,如何才能将Google+图片(通告)和Google+封面照片放入Android应用的导航抽屉中?这有API吗?另外,我们如何将个人资料照片显示为圆圈?我正在尝试使用与Android INBOX应用程序相同的导航抽屉UI。
答案 0 :(得分:17)
https://developers.google.com/+/mobile/android/getting-started#step_1_enable_the_google_api
http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
How to create a custom navigation drawer in android
https://developer.android.com/google/auth/api-client.html
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......
googleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.build();
}
@Override
public void onConnected(Bundle bundle) {
Plus.PeopleApi.loadVisible(googleApiClient, null).setResultCallback(this);
if (Plus.PeopleApi.getCurrentPerson(googleApiClient) != null) {
Person person = Plus.PeopleApi.getCurrentPerson(googleApiClient);
personNameView.setText(person.getDisplayName());
if (person.hasImage()) {
Person.Image image = person.getImage();
new AsyncTask<String, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(String... params) {
try {
URL url = new URL(params[0]);
InputStream in = url.openStream();
return BitmapFactory.decodeStream(in);
} catch (Exception e) {
/* TODO log error */
}
return null;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
personImageView.setImageBitmap(bitmap);
}
}.execute(image.getUrl());
}
}
你可以在这里找到整个例子: http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/
对于封面照片,你可以做类似的
Person.Cover.CoverPhoto cover = person.getCover().getCoverPhoto();
cover.getUrl()