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.
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
}
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.
不要在 verifyPhoneNumber(..) 方法中传递“this”,而是尝试传递 Activityname.this
方法 verifyPhoneNumber 中 TimeUnit.SECONDS 的问题您必须替换 import Class TimeUnit 以import java.util.concurrent.TimeUnit ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.