Skip to content

Commit 8b75e76

Browse files
committed
callback
1 parent 574f000 commit 8b75e76

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.simplejnius.sjfirebase.callback;
2+
3+
import androidx.annotation.NonNull;
4+
import com.google.firebase.auth.PhoneAuthCredential;
5+
import com.google.firebase.auth.PhoneAuthProvider;
6+
import com.google.firebase.FirebaseException;
7+
import androidx.annotation.NonNull;
8+
9+
10+
interface VerificationStateChangeCallback {
11+
public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken token);
12+
public abstract void onVerificationCompleted(@NonNull PhoneAuthCredential credential);
13+
public abstract void onVerificationFailed(@NonNull FirebaseException e);
14+
}

0 commit comments

Comments
 (0)