Android: How to get Google+ Profile Image and Cover Photo into Navigation Drawer

后端 未结 1 1360
借酒劲吻你
借酒劲吻你 2021-01-30 19:25

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 An

相关标签:
1条回答
  • 2021-01-30 19:51
    1. You will need Enabling G+ API on google console.

    https://developers.google.com/+/mobile/android/getting-started#step_1_enable_the_google_api

    1. 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

    1. 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()
    
    1. Circle image

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

    How to make an ImageView with rounded corners?

    0 讨论(0)
提交回复
热议问题