Google Plus帐户登录/注销无法正常运行

时间:2017-06-15 05:37:53

标签: android google-plus-signin

通过谷歌登录时无法在多个帐户(第二次及以上)中进行选择

我正在使用谷歌加登入我的Android应用程序。一切都很好。但是当我第一次尝试登录时(安装应用程序后),我可以选择不同的谷歌帐户(如果我有超过1个帐户登录我的设备) enter image description here,但是当我退出并再次登录时,它不会给我选择选项,它会自动使用之前选择的帐户登录。

我正在使用此代码进行注销。

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build();
            GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(context)
                    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                    .build();
            Auth.GoogleSignInApi.signOut(mGoogleApiClient);
            Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient);

我还浏览了signOut文档,我从中了解到“删除了Google Play服务中为您的应用设置的默认帐户”,但它不起作用。有没有解决办法呢?

任何人都可以帮助找到解决方案

2 个答案:

答案 0 :(得分:1)

它对我有用,可能对你有帮助。

连接使用时:

"sourceImageVhdUri": {
      "type": "string",
      "metadata": {
        "description": "The source of the blob containing the custom image, must be in the same region of the deployment."
      }
    },

断开连接时:

if (mGoogleApiClient == null) {

 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                                                          .requestEmail()
                                                          .requestProfile()
                                                          .build();

                 mGoogleApiClient = new GoogleApiClient.Builder(getContext())
                                               .enableAutoManage(getActivity(), new GoogleApiClient.OnConnectionFailedListener() {
                 @Override
                 public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

                                                       Log.e("Error Google Conn", "" + connectionResult.toString());
                                                   }
                                               })
                                               .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                                               .addApi(Plus.API)
                                               .addApi(AppIndex.API).build();

                    mGoogleApiClient.connect();
                }

答案 1 :(得分:0)

经过很长一段时间,我从Rahul Sonone的答案中找到了问题的答案。 他们只有在我尝试登录之前就会调用signOut。

Auth.GoogleSignInApi.signOut(mGoogleApiClient);
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
相关问题