android - 如何让用户在 google session firebase 中退出?
问题描述
这是我的代码
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 的会话,以便它询问我要重新开始的帐户
解决方案
尝试这个
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));
推荐阅读
- asp.net - 替换 Azure Blob 存储中的文件时出现错误 500
- python - ValueError:预期可迭代原始文本文档,接收到字符串对象。使用 tfidf 和选择功能预测新的测试数据
- javascript - 从Dojo中的Checked Multi Select(“dojox.form.CheckedMultiSelect”)中选择选项时如何编写条件?
- kubernetes - 启用 istio 时 Postgres Kubernetes Helm 图表失败
- mysql - 如果值为 x 或 y,则 MySQL 更新
- java - 如何将类传递给 Kotlin 中的函数
- c++ - QtConcurrent - 在发布到 UI 线程的数千个结果中保持 GUI 响应
- android - DatabaseReference 'setValue' Android Studio 显示错误
- android - 收到错误 android.util.SuperNotCalledException: Activity {} 没有调用 super.onCreate()
- asp.net - 文本未在材料 UI 核心中选择下拉列表的中心垂直对齐