got a problem with built-in function signInWithCredential. I have no idea what's wrong, trying most thing from Stack and different sites... If I change "?" to "!!" after mAuth I got error:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=-1, data=Intent { (has extras) }} to activity (...) java.lang.NullPointerException
Here is the handleFacebookAcessToken function
private fun handleFacebookAccesToken(accessToken: AccessToken?) {
val progressDialog = ProgressDialog(this@MainActivity)
progressDialog.setTitle("Sign Up with Facebook")
progressDialog.setMessage("Please wait, this may take a while...")
progressDialog.setCanceledOnTouchOutside(false)
progressDialog.show()
val credential = FacebookAuthProvider.getCredential(accessToken!!.token)
val mAuth: FirebaseAuth? = null
mAuth?.signInWithCredential(credential)
?.addOnCompleteListener(this) { task ->
if (task.isSuccessful)
{
val intent = Intent(this, Activity2::class.java)
startActivity(intent)
progressDialog.dismiss()
val user: FirebaseUser = FirebaseAuth.getInstance().currentUser!!
//updateUI(user)
}
else
{
val message = task.exception!!.toString()
Toast.makeText(this, "Error: $message", Toast.LENGTH_LONG).show()
mAuth?.signOut()
progressDialog.dismiss()
}
}
}
Also the two more functions which can be wrong
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
callbackManager?.onActivityResult(requestCode, resultCode, data)
}
private fun SignInWithFacebook()
{
if (BuildConfig.DEBUG) {
FacebookSdk.setIsDebugEnabled(true)
FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS)
}
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"))
LoginManager.getInstance().registerCallback(callbackManager,
object : FacebookCallback<LoginResult>
{
override fun onSuccess(result: LoginResult?) {
handleFacebookAccesToken(result!!.accessToken)
}
override fun onCancel() {
}
override fun onError(error: FacebookException?) {
Toast.makeText(applicationContext, "Error!", Toast.LENGTH_LONG).show()
}
})
}
Sorry if I asked something wrong, it's my first post