How to create Phone OTP Authentication in Sketchware
Code for send otp :
com.google.firebase.auth.PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber,
(long)60, java.util.concurrent.TimeUnit.SECONDS,
MainActivity.this,
mCallback
);
Code for Moreblock :
}
com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallback = new com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(com.google.firebase.auth.PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(MainActivity.this,"Code Received",Toast.LENGTH_SHORT).show();
}
@Override
public void onVerificationFailed(com.google.firebase.FirebaseException e) {
//if verification failed Toast.makeText(MainActivity.this,"verification fialed",Toast.LENGTH_SHORT).show();
}
@Override
public void onCodeSent(String s, com.google.firebase.auth.PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verificationCode = s;
//if success add your command here
//If error
Toast.makeText(MainActivity.this,"Code sent",Toast.LENGTH_SHORT).show();
}
};
{
Code for verify OTP:
com.google.firebase.auth.PhoneAuthCredential credential = com.google.firebase.auth.PhoneAuthProvider.getCredential(verificationCode, otp);
auth.signInWithCredential(credential).addOnCompleteListener(MainActivity.this, _auth_sign_in_listener);
A tutorial video is attached below:
com.google.firebase.auth.PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber,
(long)60, java.util.concurrent.TimeUnit.SECONDS,
MainActivity.this,
mCallback
);
Code for Moreblock :
}
com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallback = new com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(com.google.firebase.auth.PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(MainActivity.this,"Code Received",Toast.LENGTH_SHORT).show();
}
@Override
public void onVerificationFailed(com.google.firebase.FirebaseException e) {
//if verification failed Toast.makeText(MainActivity.this,"verification fialed",Toast.LENGTH_SHORT).show();
}
@Override
public void onCodeSent(String s, com.google.firebase.auth.PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verificationCode = s;
//if success add your command here
//If error
Toast.makeText(MainActivity.this,"Code sent",Toast.LENGTH_SHORT).show();
}
};
{
Code for verify OTP:
com.google.firebase.auth.PhoneAuthCredential credential = com.google.firebase.auth.PhoneAuthProvider.getCredential(verificationCode, otp);
auth.signInWithCredential(credential).addOnCompleteListener(MainActivity.this, _auth_sign_in_listener);
A tutorial video is attached below:
Comments
Post a Comment