【问题标题】:Google Account Logout from android app从 Android 应用程序中注销 Google 帐户
【发布时间】:2016-12-09 05:41:07
【问题描述】:

如果我的应用程序可以选择使用谷歌帐户登录,我该如何退出? 注销是从另一个活动完成的。我怎样才能做到这一点? 请帮忙..

【问题讨论】:

    标签: android android-activity logout google-signin


    【解决方案1】:

    首先像这样在 onCreate 方法中与 Google 建立联系 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build();

        GoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, this)
                .addOnConnectionFailedListener(this)
                .addConnectionCallbacks(this)
                .addApi(Auth.GOOGLE_SIGN_IN_API)
                .build();
    

    GoogleApiClient.connect();

    然后:

      Auth.GoogleSignInApi.signOut(GoogleApiClient).setResultCallback(
                        new ResultCallback<Status>() {
    
    
                            @Override
                            public void onResult(Status status) {
                                sessionManager.clearSession();
                                Intent i=new Intent(getApplicationContext(),MainActivity.class);
                                startActivity(i);
                                finish();
                                Toast.makeText(getApplicationContext(),"Logout Successfully",Toast.LENGTH_LONG).show();
                            }
                        });
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-26
      • 2015-03-11
      • 1970-01-01
      • 1970-01-01
      • 2016-06-03
      • 2012-12-28
      • 1970-01-01
      相关资源
      最近更新 更多