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

cod*_*ark 6 android google-plus navigation-drawer

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

usi*_*sil 17

  1. 您需要在Google控制台上启用G + API.

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

  1. 您需要制作自定义导航抽屉:

http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

如何在android中创建自定义导航抽屉

  1. 您需要初始化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());
            }
       }
Run Code Online (Sandbox Code Playgroud)

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

对于封面照片,你可以做类似的

Person.Cover.CoverPhoto cover = person.getCover().getCoverPhoto();
cover.getUrl()
Run Code Online (Sandbox Code Playgroud)
  1. 圆形图像

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

如何制作带圆角的ImageView?