Android的:如何获得Google+个人资料图片和封面照片为抽屉式导航 [英] Android: How to get Google+ Profile Image and Cover Photo into Navigation Drawer
问题描述
假设登录到手机上其Google+帐户的用户,怎样才能获得的Google+图片(圆形)和Google+的封面照片成一个Android应用程序的导航抽屉?是否有一个这样的API?此外,我们怎么能显示个人资料照片是一个圆?我想达到同样的抽屉式导航UI的Android的INBOX应用程序。
- 您将需要启用G + API在谷歌控制台。
<一个href="https://developers.google.com/+/mobile/android/getting-started#step_1_enable_the_google_api">https://developers.google.com/+/mobile/android/getting-started#step_1_enable_the_google_api
<醇开始=2><一个href="http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/">http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
<一个href="http://stackoverflow.com/questions/21796209/how-to-create-a-custom-navigation-drawer-in-android">How在Android的创建一个自定义导航抽屉
<醇开始=3><一个href="https://developer.android.com/google/auth/api-client.html">https://developer.android.com/google/auth/api-client.html
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
......
googleApiClient =新GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(本)
.addOnConnectionFailedListener(本)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
。建立();
}
@覆盖
公共无效onConnected(束捆){
Plus.PeopleApi.loadVisible(googleApiClient,空).setResultCallback(本);
如果(Plus.PeopleApi.getCurrentPerson(googleApiClient)!= NULL){
人人= Plus.PeopleApi.getCurrentPerson(googleApiClient);
personNameView.setText(person.getDisplayName());
如果(person.hasImage()){
Person.Image图像= person.getImage();
新的AsyncTask&LT;字符串,太虚,位图&GT;(){
@覆盖
受保护的位图doInBackground(字符串... PARAMS){
尝试 {
网址URL =新的URL(PARAMS [0]);
在的InputStream = url.openStream();
返回BitmapFactory.de codeStream(中);
}赶上(例外五){
/ * TODO日志错误* /
}
返回null;
}
@覆盖
保护无效onPostExecute(位图位图){
personImageView.setImageBitmap(位);
}
} .execute(image.getUrl());
}
}
整个例如,你可以在这里: <一href="http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/">http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/
有关封面照片,你可以做类似的
Person.Cover.CoverPhoto覆盖= person.getCover()getCoverPhoto()。
cover.getUrl()
<醇开始=4>
<一个href="http://curious-blog.blogspot.com/2014/05/create-circle-bitmap-in-android.html">http://curious-blog.blogspot.com/2014/05/create-circle-bitmap-in-android.html
如何使圆角 <一个ImageView的/ P>
Assuming the user is logged into their Google+ account on the phone, How can one get the Google+ Image (circular) and the Google+ Cover Photo into the Navigation Drawer of an Android app? Is there an API for this? Also, how can we display the profile photo as a circle? I am trying to achieve the same navigation drawer UI as the Android INBOX app.
- You will need Enabling G+ API on google console.
https://developers.google.com/+/mobile/android/getting-started#step_1_enable_the_google_api
- You will need to make custom navigation drawer:
http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
How to create a custom navigation drawer in android
- You will need to initialize the GoogleApiClient
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());
}
}
The whole example you can get here: http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/
For cover photo you can do similar
Person.Cover.CoverPhoto cover = person.getCover().getCoverPhoto();
cover.getUrl()
- Circle image
http://curious-blog.blogspot.com/2014/05/create-circle-bitmap-in-android.html
How to make an ImageView with rounded corners
这篇关于Android的:如何获得Google+个人资料图片和封面照片为抽屉式导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!