Reputation: 393
Im kinda new to firebase and android then I saw this new feature in android the firebase phone Auth. I was looking at this doucumentation Firebase Phone Auth and I am confused on Implementing this mCallbacks .. can someone pls guide me ?
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNum,
60,
TimeUnit.SECONDS,
this,
mCallbacks
this confused me is I dont know what data type should I use to assign that callback. since there is no sample code I wish someone might able to guide me.
Upvotes: 4
Views: 4950
Reputation: 52
The problem at TimeUnit.SECONDS in Method verifyPhoneNumber you must replace the import Class TimeUnit to import java.util.concurrent.TimeUnit;
Upvotes: 0
Reputation: 69
Instead of passing "this" inside the verifyPhoneNumber(..) method, Try to pass Activityname.this
Upvotes: 0
Reputation: 393
I believe this solved my problem.
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phoneNum = editText.getText().toString();
Toast.makeText(MainActivity.this, phoneNum, Toast.LENGTH_SHORT).show();
verifyPhone(phoneNum,mCallBacks);
}
});
I tried to make a method to handle the button clicked, I dont know why but it worked..
public void verifyPhone(String phoneNumber, PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks){
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbac
}
Upvotes: 2
Reputation: 37798
You should use a PhoneAuthProvider.OnVerificationStateChangedCallbacks()
. Like so:
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
}
@Override
public void onVerificationFailed(FirebaseException e) {
}
});
Then you could just override the other Verification callbacks that you need.
Upvotes: 2