Android:如何将Google+个人资料图片和封面照片导入导航抽屉

时间:2014-11-20 07:22:59

标签: android google-plus navigation-drawer

假设用户已在手机上登录其Google+帐户,如何才能将Google+图片(通告)和Google+封面照片放入Android应用的导航抽屉中?这有API吗?另外,我们如何将个人资料照片显示为圆圈?我正在尝试使用与Android INBOX应用程序相同的导航抽屉UI。

1 个答案:

答案 0 :(得分:17)

  1. 您需要在Google控制台上启用G + API。
  2. https://developers.google.com/+/mobile/android/getting-started#step_1_enable_the_google_api

    1. 您需要制作自定义导航抽屉:
    2. http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

      How to create a custom navigation drawer in android

      1. 您需要初始化GoogleApiClient
      2. 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()
        
        1. 圆圈图片
        2. http://curious-blog.blogspot.com/2014/05/create-circle-bitmap-in-android.html

          How to make an ImageView with rounded corners?

相关问题