Firebase Phone Authentication has Stopped
I am new to Firebase and Kotlin. I tested below code for OTP number generation but I am getting Firebase Phone Authentication has stopped Error and crashing the app. I am not sure whether I need FireBase Authentication account and where do I need to pass the credentials in the code. Thanks for your response.
MainActivity:
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity()
lateinit var mAuth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mAuth = FirebaseAuth.getInstance()
signOut.setOnClickListener
view: View? -> mAuth.signOut()
startActivity(Intent(this, PhoneAuthentication::class.java))
Toast.makeText(this, "Logged out Successfully :)", Toast.LENGTH_LONG).show()
override fun onStart()
super.onStart()
if (mAuth.currentUser == null)
startActivity(Intent(this, PhoneAuthentication::class.java))
else
Toast.makeText(this, "Already Signed in :)", Toast.LENGTH_LONG).show()
PhoneAuthentication.kt
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.google.android.gms.tasks.Task
import com.google.firebase.FirebaseException
import com.google.firebase.auth.AuthResult
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.PhoneAuthCredential
import com.google.firebase.auth.PhoneAuthProvider
import kotlinx.android.synthetic.main.activity_phone_authentication.*
import java.util.concurrent.TimeUnit
class PhoneAuthentication : AppCompatActivity()
lateinit var mCallbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks
lateinit var mAuth: FirebaseAuth
var verificationId = ""
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_phone_authentication)
mAuth = FirebaseAuth.getInstance()
veriBtn.setOnClickListener
view: View? -> progress.visibility = View.VISIBLE
verify ()
authBtn.setOnClickListener
view: View? -> progress.visibility = View.VISIBLE
authenticate()
private fun verificationCallbacks ()
mCallbacks = object: PhoneAuthProvider.OnVerificationStateChangedCallbacks()
override fun onVerificationCompleted(credential: PhoneAuthCredential)
progress.visibility = View.INVISIBLE
toast("LoggedIn Success :) "+ credential)
signIn(credential)
override fun onVerificationFailed(p0: FirebaseException?)
TODO("not implemented") //To change body of created functions use File
override fun onCodeSent(verfication: String?, p1: PhoneAuthProvider.ForceResendingToken?)
// super.onCodeSent(verfication, p1)
verificationId = verfication.toString()
progress.visibility = View.INVISIBLE
private fun verify ()
verificationCallbacks()
if(phnNoTxt.text.length>=13)
val phnNo = phnNoTxt.text.toString()
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phnNo,
60,
TimeUnit.SECONDS,
this,
mCallbacks
)
else
toast("please enter a valid contact number with country code!!")
progress.visibility = View.INVISIBLE
private fun signIn (credential: PhoneAuthCredential)
mAuth.signInWithCredential(credential)
.addOnCompleteListener
task: Task<AuthResult> ->
if (task.isSuccessful)
toast("LoggedIn Success !!)")
startActivity(Intent(this, MainActivity::class.java))
private fun authenticate ()
val verifiNo = verifiTxt.text.toString()
val credential: PhoneAuthCredential = PhoneAuthProvider.getCredential(verificationId, verifiNo)
signIn(credential)
private fun toast (msg: String)
Toast.makeText(this, msg, Toast.LENGTH_LONG).show()
ExampleInstrumentedTest.kt
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest
@Test
fun useAppContext()
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.winision.phoneauth", appContext.packageName)
android firebase kotlin firebase-authentication kotlin-android-extensions
add a comment |
I am new to Firebase and Kotlin. I tested below code for OTP number generation but I am getting Firebase Phone Authentication has stopped Error and crashing the app. I am not sure whether I need FireBase Authentication account and where do I need to pass the credentials in the code. Thanks for your response.
MainActivity:
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity()
lateinit var mAuth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mAuth = FirebaseAuth.getInstance()
signOut.setOnClickListener
view: View? -> mAuth.signOut()
startActivity(Intent(this, PhoneAuthentication::class.java))
Toast.makeText(this, "Logged out Successfully :)", Toast.LENGTH_LONG).show()
override fun onStart()
super.onStart()
if (mAuth.currentUser == null)
startActivity(Intent(this, PhoneAuthentication::class.java))
else
Toast.makeText(this, "Already Signed in :)", Toast.LENGTH_LONG).show()
PhoneAuthentication.kt
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.google.android.gms.tasks.Task
import com.google.firebase.FirebaseException
import com.google.firebase.auth.AuthResult
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.PhoneAuthCredential
import com.google.firebase.auth.PhoneAuthProvider
import kotlinx.android.synthetic.main.activity_phone_authentication.*
import java.util.concurrent.TimeUnit
class PhoneAuthentication : AppCompatActivity()
lateinit var mCallbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks
lateinit var mAuth: FirebaseAuth
var verificationId = ""
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_phone_authentication)
mAuth = FirebaseAuth.getInstance()
veriBtn.setOnClickListener
view: View? -> progress.visibility = View.VISIBLE
verify ()
authBtn.setOnClickListener
view: View? -> progress.visibility = View.VISIBLE
authenticate()
private fun verificationCallbacks ()
mCallbacks = object: PhoneAuthProvider.OnVerificationStateChangedCallbacks()
override fun onVerificationCompleted(credential: PhoneAuthCredential)
progress.visibility = View.INVISIBLE
toast("LoggedIn Success :) "+ credential)
signIn(credential)
override fun onVerificationFailed(p0: FirebaseException?)
TODO("not implemented") //To change body of created functions use File
override fun onCodeSent(verfication: String?, p1: PhoneAuthProvider.ForceResendingToken?)
// super.onCodeSent(verfication, p1)
verificationId = verfication.toString()
progress.visibility = View.INVISIBLE
private fun verify ()
verificationCallbacks()
if(phnNoTxt.text.length>=13)
val phnNo = phnNoTxt.text.toString()
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phnNo,
60,
TimeUnit.SECONDS,
this,
mCallbacks
)
else
toast("please enter a valid contact number with country code!!")
progress.visibility = View.INVISIBLE
private fun signIn (credential: PhoneAuthCredential)
mAuth.signInWithCredential(credential)
.addOnCompleteListener
task: Task<AuthResult> ->
if (task.isSuccessful)
toast("LoggedIn Success !!)")
startActivity(Intent(this, MainActivity::class.java))
private fun authenticate ()
val verifiNo = verifiTxt.text.toString()
val credential: PhoneAuthCredential = PhoneAuthProvider.getCredential(verificationId, verifiNo)
signIn(credential)
private fun toast (msg: String)
Toast.makeText(this, msg, Toast.LENGTH_LONG).show()
ExampleInstrumentedTest.kt
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest
@Test
fun useAppContext()
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.winision.phoneauth", appContext.packageName)
android firebase kotlin firebase-authentication kotlin-android-extensions
If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question. Without it, we cannot be much of a help.
– Alex Mamo
Nov 12 '18 at 11:13
add a comment |
I am new to Firebase and Kotlin. I tested below code for OTP number generation but I am getting Firebase Phone Authentication has stopped Error and crashing the app. I am not sure whether I need FireBase Authentication account and where do I need to pass the credentials in the code. Thanks for your response.
MainActivity:
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity()
lateinit var mAuth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mAuth = FirebaseAuth.getInstance()
signOut.setOnClickListener
view: View? -> mAuth.signOut()
startActivity(Intent(this, PhoneAuthentication::class.java))
Toast.makeText(this, "Logged out Successfully :)", Toast.LENGTH_LONG).show()
override fun onStart()
super.onStart()
if (mAuth.currentUser == null)
startActivity(Intent(this, PhoneAuthentication::class.java))
else
Toast.makeText(this, "Already Signed in :)", Toast.LENGTH_LONG).show()
PhoneAuthentication.kt
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.google.android.gms.tasks.Task
import com.google.firebase.FirebaseException
import com.google.firebase.auth.AuthResult
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.PhoneAuthCredential
import com.google.firebase.auth.PhoneAuthProvider
import kotlinx.android.synthetic.main.activity_phone_authentication.*
import java.util.concurrent.TimeUnit
class PhoneAuthentication : AppCompatActivity()
lateinit var mCallbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks
lateinit var mAuth: FirebaseAuth
var verificationId = ""
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_phone_authentication)
mAuth = FirebaseAuth.getInstance()
veriBtn.setOnClickListener
view: View? -> progress.visibility = View.VISIBLE
verify ()
authBtn.setOnClickListener
view: View? -> progress.visibility = View.VISIBLE
authenticate()
private fun verificationCallbacks ()
mCallbacks = object: PhoneAuthProvider.OnVerificationStateChangedCallbacks()
override fun onVerificationCompleted(credential: PhoneAuthCredential)
progress.visibility = View.INVISIBLE
toast("LoggedIn Success :) "+ credential)
signIn(credential)
override fun onVerificationFailed(p0: FirebaseException?)
TODO("not implemented") //To change body of created functions use File
override fun onCodeSent(verfication: String?, p1: PhoneAuthProvider.ForceResendingToken?)
// super.onCodeSent(verfication, p1)
verificationId = verfication.toString()
progress.visibility = View.INVISIBLE
private fun verify ()
verificationCallbacks()
if(phnNoTxt.text.length>=13)
val phnNo = phnNoTxt.text.toString()
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phnNo,
60,
TimeUnit.SECONDS,
this,
mCallbacks
)
else
toast("please enter a valid contact number with country code!!")
progress.visibility = View.INVISIBLE
private fun signIn (credential: PhoneAuthCredential)
mAuth.signInWithCredential(credential)
.addOnCompleteListener
task: Task<AuthResult> ->
if (task.isSuccessful)
toast("LoggedIn Success !!)")
startActivity(Intent(this, MainActivity::class.java))
private fun authenticate ()
val verifiNo = verifiTxt.text.toString()
val credential: PhoneAuthCredential = PhoneAuthProvider.getCredential(verificationId, verifiNo)
signIn(credential)
private fun toast (msg: String)
Toast.makeText(this, msg, Toast.LENGTH_LONG).show()
ExampleInstrumentedTest.kt
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest
@Test
fun useAppContext()
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.winision.phoneauth", appContext.packageName)
android firebase kotlin firebase-authentication kotlin-android-extensions
I am new to Firebase and Kotlin. I tested below code for OTP number generation but I am getting Firebase Phone Authentication has stopped Error and crashing the app. I am not sure whether I need FireBase Authentication account and where do I need to pass the credentials in the code. Thanks for your response.
MainActivity:
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity()
lateinit var mAuth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mAuth = FirebaseAuth.getInstance()
signOut.setOnClickListener
view: View? -> mAuth.signOut()
startActivity(Intent(this, PhoneAuthentication::class.java))
Toast.makeText(this, "Logged out Successfully :)", Toast.LENGTH_LONG).show()
override fun onStart()
super.onStart()
if (mAuth.currentUser == null)
startActivity(Intent(this, PhoneAuthentication::class.java))
else
Toast.makeText(this, "Already Signed in :)", Toast.LENGTH_LONG).show()
PhoneAuthentication.kt
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.google.android.gms.tasks.Task
import com.google.firebase.FirebaseException
import com.google.firebase.auth.AuthResult
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.PhoneAuthCredential
import com.google.firebase.auth.PhoneAuthProvider
import kotlinx.android.synthetic.main.activity_phone_authentication.*
import java.util.concurrent.TimeUnit
class PhoneAuthentication : AppCompatActivity()
lateinit var mCallbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks
lateinit var mAuth: FirebaseAuth
var verificationId = ""
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_phone_authentication)
mAuth = FirebaseAuth.getInstance()
veriBtn.setOnClickListener
view: View? -> progress.visibility = View.VISIBLE
verify ()
authBtn.setOnClickListener
view: View? -> progress.visibility = View.VISIBLE
authenticate()
private fun verificationCallbacks ()
mCallbacks = object: PhoneAuthProvider.OnVerificationStateChangedCallbacks()
override fun onVerificationCompleted(credential: PhoneAuthCredential)
progress.visibility = View.INVISIBLE
toast("LoggedIn Success :) "+ credential)
signIn(credential)
override fun onVerificationFailed(p0: FirebaseException?)
TODO("not implemented") //To change body of created functions use File
override fun onCodeSent(verfication: String?, p1: PhoneAuthProvider.ForceResendingToken?)
// super.onCodeSent(verfication, p1)
verificationId = verfication.toString()
progress.visibility = View.INVISIBLE
private fun verify ()
verificationCallbacks()
if(phnNoTxt.text.length>=13)
val phnNo = phnNoTxt.text.toString()
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phnNo,
60,
TimeUnit.SECONDS,
this,
mCallbacks
)
else
toast("please enter a valid contact number with country code!!")
progress.visibility = View.INVISIBLE
private fun signIn (credential: PhoneAuthCredential)
mAuth.signInWithCredential(credential)
.addOnCompleteListener
task: Task<AuthResult> ->
if (task.isSuccessful)
toast("LoggedIn Success !!)")
startActivity(Intent(this, MainActivity::class.java))
private fun authenticate ()
val verifiNo = verifiTxt.text.toString()
val credential: PhoneAuthCredential = PhoneAuthProvider.getCredential(verificationId, verifiNo)
signIn(credential)
private fun toast (msg: String)
Toast.makeText(this, msg, Toast.LENGTH_LONG).show()
ExampleInstrumentedTest.kt
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest
@Test
fun useAppContext()
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.winision.phoneauth", appContext.packageName)
android firebase kotlin firebase-authentication kotlin-android-extensions
android firebase kotlin firebase-authentication kotlin-android-extensions
edited Nov 12 '18 at 7:38
PradyumanDixit
1
1
asked Nov 12 '18 at 2:41
user10638374
If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question. Without it, we cannot be much of a help.
– Alex Mamo
Nov 12 '18 at 11:13
add a comment |
If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question. Without it, we cannot be much of a help.
– Alex Mamo
Nov 12 '18 at 11:13
If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question. Without it, we cannot be much of a help.
– Alex Mamo
Nov 12 '18 at 11:13
If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question. Without it, we cannot be much of a help.
– Alex Mamo
Nov 12 '18 at 11:13
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255339%2ffirebase-phone-authentication-has-stopped%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255339%2ffirebase-phone-authentication-has-stopped%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question. Without it, we cannot be much of a help.
– Alex Mamo
Nov 12 '18 at 11:13