来自Android应用的Google帐户退出

时间:2016-12-09 05:41:08

标签: android android-activity logout google-signin

如何从我的应用程序注销,可以选择使用Google帐户登录? 注销是从另一个活动完成的。我能实现吗? 请帮忙..

1 个答案:

答案 0 :(得分:0)

首先与Google建立联系,就像在onCreate方法中编写此代码一样    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();
                        }
                    });
        }