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

2024-04-19

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


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

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

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

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

如何在android中创建自定义导航抽屉 https://stackoverflow.com/questions/21796209/how-to-create-a-custom-navigation-drawer-in-android

  1. 您需要初始化 GoogleApiClient

https://developer.android.com/google/auth/api-client.html 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/ http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/

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

Person.Cover.CoverPhoto cover = person.getCover().getCoverPhoto();
cover.getUrl()
  1. 圆形图像

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? https://stackoverflow.com/questions/2459916/how-to-make-an-imageview-with-rounded-corners

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android:如何将 Google+ 个人资料图片和封面照片放入导航抽屉中 的相关文章

随机推荐