这是我的代码
val googleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build()
googleApiClient = GoogleApiClient.Builder(this)
.enableAutoManage(this){}
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.build()
}
override fun onClick(view: View?) {
when (view?.id) {
R.id.google_sign_in_button -> {
Log.i(TAG, "Trying Google LogIn.")
googleLogin()
}
}
}
private fun googleLogin() {
val signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient)
startActivityForResult(signInIntent, 1)
}
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == 1) {
val result = Auth.GoogleSignInApi.getSignInResultFromIntent(data)
if (result.isSuccess) {
// Google Sign In was successful, authenticate with Firebase
firebaseAuthWithGoogle(result.signInAccount!!)
} else {
Toast.makeText(this, "Some error occurred.", Toast.LENGTH_SHORT).show()
}
}
}
private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount) {
val credential = GoogleAuthProvider.getCredential(acct.idToken, null)
firebaseAuth?.signInWithCredential(credential)?.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
startActivity(Intent(this, prueba::class.java))
} else {
// If sign in fails, display a message to the user.
}
}
}
当会话开始时,它会带我去另一个活动。 问题是我如何从其他活动中关闭该会话。 我想关闭google而不是firebase的会话,以便它询问我想要重新开始的帐户
答案 0 :(得分:0)
试试这个
mGoogleSignInClient.signOut();
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(SettingsActivity.this, gso);
这会让您退出Google,但要将用户带回登录页面,请使用
startActivity(new Intent(WhateverActivityItsOn.this, BacktoSignInPageActivity.class));