Created
August 17, 2018 14:01
-
-
Save vprabhu/6beca8480716ef7636d7b8a5e9af93c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 == RC_SIGN_IN) { | |
val result = Auth.GoogleSignInApi.getSignInResultFromIntent(data) | |
if (result.isSuccess) { | |
// Google Sign In was successful, authenticate with Firebase | |
val account = result.signInAccount | |
firebaseAuthWithGoogle(account!!) | |
} else { | |
// Google Sign In failed | |
Log.e("MainActivity", "Google Sign In failed.") | |
} | |
} | |
} | |
private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount) { | |
Log.d("Login", "firebaseAuthWithGoogle:" + acct.id!!) | |
val credential = GoogleAuthProvider.getCredential(acct.idToken, null) | |
mAuth.signInWithCredential(credential) | |
.addOnCompleteListener(this, OnCompleteListener<AuthResult> { task -> | |
Log.d("Login", "signInWithCredential:onComplete:" + task.isSuccessful) | |
// If sign in fails, display a message to the user. If sign in succeeds | |
// the auth state listener will be notified and logic to handle the | |
// signed in user can be handled in the listener. | |
if (!task.isSuccessful) { | |
Log.d("Login", "signInWithCredential", task.exception) | |
Toast.makeText(this@LoginActivity, "Authentication failed.", | |
Toast.LENGTH_SHORT).show() | |
} else { | |
setLoginUIVisible(task.result?.user?.photoUrl) | |
textView_username.text = task.result?.user?.displayName | |
// textView_username.text = task.result?.user?.photoUrl.toString() | |
Glide.with(this@LoginActivity) | |
.load(task.result?.user?.photoUrl) | |
.into(imageView_profilePic) | |
setLogoutUI() | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment