如何从我的应用程序注销,可以选择使用Google帐户登录? 注销是从另一个活动完成的。我能实现吗? 请帮忙..
答案 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();
}
});
}