Android的:如何获得Google+个人资料图片和封面照片为抽屉式导航如何获得、封面、个人资料、照片

2023-09-04 23:54:16 作者:鸽屿

假设登录到手机上其Google+帐户的用户,怎样才能获得的Google+图片(圆形)和Google+的封面照片成一个Android应用程序的导航抽屉?是否有一个这样的API?此外,我们怎么能显示个人资料照片是一个圆?我想达到同样的抽屉式导航UI的Andr​​oid的INBOX应用程序。

解决方案 您将需要启用G + API在谷歌控制台。

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在Android的创建一个自定义导航抽屉

您需要初始化GoogleApiClient

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<字符串,太虚,位图>(){

                    @覆盖
                    受保护的位图doInBackground(字符串... PARAMS){

                        尝试 {
                            网址URL =新的URL(PARAMS [0]);
                            在的InputStream = url.openStream();
                            返回BitmapFactory.de codeStream(中);
                        }赶上(例外五){
                        / * TODO日志错误* /
                        }
                        返回null;
                    }

                    @覆盖
                    保护无效onPostExecute(位图位图){
                        personImageView.setImageBitmap(位);
                    }
                } .execute(image.getUrl());
            }
       }
 

整个例如,你可以在这里: http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/

有关封面照片,你可以做类似的

  Person.Cover.CoverPhoto覆盖= person.getCover()getCoverPhoto()。
cover.getUrl()
 
文章图片Android 4.0即将发布 谷歌音乐4.0曝光 共9张

圈图片

http://curious-blog.blogspot.com/2014/05/create-circle-bitmap-in-android.html

如何使圆角

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