【问题标题】:Android: How to get Google+ Profile Image and Cover Photo into Navigation DrawerAndroid:如何将 Google+ 个人资料图片和封面照片放入导航抽屉
【发布时间】:2014-11-20 07:22:59
【问题描述】:

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

【问题讨论】:

标签: android google-plus navigation-drawer


【解决方案1】:
  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/

How to create a custom navigation drawer in 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());
            }
       }

您可以在此处获取整个示例: 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

How to make an ImageView with rounded corners?

【讨论】:

  • 我通过从 Google API 获取 URi 解决了类似的问题,然后从个人资料信息中的照片获取。 .execute(acct.getPhotoUrl().toString());
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多