728x90
//공식문서에서 문제 되는 부분
// [START signin]
private fun signIn() {
val signInIntent = googleSignInClient.signInIntent
startActivityForResult(signInIntent, RC_SIGN_IN)
}
// [END signin]
이부분을
// [START signin]
private fun googleSignIn() {
val signInIntent = googleSignInClient.signInIntent
resultLauncher.launch(signInIntent)
}
private var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
// There are no request codes
val data = result.data
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
// Google Sign In was successful, authenticate with Firebase
val account = task.getResult(ApiException::class.java)!!
Log.d(LogTag, "firebaseAuthWithGoogle:" + account.email)
firebaseAuthWithGoogle(account.idToken!!)
Toast.makeText(this, "구글 로그인에 성공했습니다.", Toast.LENGTH_SHORT).show()
} catch (e: ApiException) {
// Google Sign In failed, update UI appropriately
Log.d(LogTag, "Google sign in failed", e)
Toast.makeText(this, "구글 로그인에 실패했습니다.", Toast.LENGTH_SHORT).show()
}
}
}
이렇게 바꿔서 사용 하면 된다.
728x90