1+ package com .simplejnius .sjfirebase .callback ;
2+
3+ import com .google .firebase .auth .PhoneAuthProvider ;
4+ import androidx .annotation .NonNull ;
5+ import com .google .firebase .auth .PhoneAuthCredential ;
6+ import com .google .firebase .FirebaseException ;
7+
8+
9+ public abstract class VerificationStateChange extends PhoneAuthProvider .OnVerificationStateChangedCallbacks {
10+ public static VerificationStateChangeCallback callback = null ;
11+
12+ public void setCallback (VerificationStateChangeCallback callback ) {
13+ this .callback = callback ;
14+ }
15+
16+ @ Override
17+ public void onVerificationCompleted (@ NonNull PhoneAuthCredential credential ) {
18+ // This callback will be invoked in two situations:
19+ // 1 - Instant verification. In some cases the phone number can be instantly
20+ // verified without needing to send or enter a verification code.
21+ // 2 - Auto-retrieval. On some devices Google Play services can automatically
22+ // detect the incoming verification SMS and perform verification without
23+ // user action.
24+
25+ callback .onVerificationCompleted (credential );
26+ }
27+
28+ @ Override
29+ public void onVerificationFailed (@ NonNull FirebaseException e ) {
30+ // This callback is invoked in an invalid request for verification is made,
31+ // for instance if the the phone number format is not valid.
32+
33+ callback .onVerificationFailed (e );
34+
35+ // Show a message and update the UI
36+ }
37+
38+ @ Override
39+ public void onCodeSent (@ NonNull String verificationId ,
40+ @ NonNull PhoneAuthProvider .ForceResendingToken token ) {
41+ // The SMS verification code has been sent to the provided phone number, we
42+ // now need to ask the user to enter the code and then construct a credential
43+ // by combining the code with a verification ID.
44+
45+ callback .onCodeSent (verificationId , token );
46+ }
47+ }
0 commit comments