|
| 1 | +package com.simplejnius.sjfirebase; |
| 2 | + |
| 3 | +import android.app.Activity; |
| 4 | + |
| 5 | +import androidx.annotation.NonNull; |
| 6 | + |
| 7 | +import com.google.firebase.auth.FirebaseAuth; |
| 8 | +import com.google.firebase.auth.PhoneAuthCredential; |
| 9 | +import com.google.firebase.auth.PhoneAuthOptions; |
| 10 | +import com.google.firebase.auth.PhoneAuthProvider; |
| 11 | +import com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks; |
| 12 | + |
| 13 | +import java.util.concurrent.TimeUnit; |
| 14 | + |
| 15 | +public class SJFirebaseAuthPhone { |
| 16 | + private static final String TAG = "AuthPhone"; |
| 17 | + private static FirebaseAuth m_auth; |
| 18 | + |
| 19 | + public static FirebaseAuth get_instance() { |
| 20 | + m_auth = FirebaseAuth.getInstance(); |
| 21 | + return m_auth; |
| 22 | + } |
| 23 | + public static void startPhoneNumberVerification( |
| 24 | + String phone_number, |
| 25 | + Long timeout, |
| 26 | + @NonNull Activity activity, |
| 27 | + OnVerificationStateChangedCallbacks callbacks |
| 28 | + ) { |
| 29 | + PhoneAuthOptions options = PhoneAuthOptions.newBuilder(get_instance()) |
| 30 | + .setPhoneNumber(phone_number) |
| 31 | + .setTimeout(timeout, TimeUnit.SECONDS) |
| 32 | + .setActivity(activity) |
| 33 | + .setCallbacks(callbacks) |
| 34 | + .build(); |
| 35 | + PhoneAuthProvider.verifyPhoneNumber(options); |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + public static void resendVerificationCode( |
| 40 | + String phone_number, |
| 41 | + Long timeout, |
| 42 | + @NonNull Activity activity, |
| 43 | + OnVerificationStateChangedCallbacks callbacks, |
| 44 | + PhoneAuthProvider.ForceResendingToken token |
| 45 | + ) { |
| 46 | + PhoneAuthOptions options = PhoneAuthOptions.newBuilder(get_instance()) |
| 47 | + .setPhoneNumber(phone_number) |
| 48 | + .setTimeout(timeout, TimeUnit.SECONDS) |
| 49 | + .setActivity(activity) |
| 50 | + .setCallbacks(callbacks) |
| 51 | + .setForceResendingToken(token) |
| 52 | + .build(); |
| 53 | + PhoneAuthProvider.verifyPhoneNumber(options); |
| 54 | + } |
| 55 | + |
| 56 | + private PhoneAuthCredential verifyPhoneNumberWithCode(String verificationId, String code) { |
| 57 | + return PhoneAuthProvider.getCredential(verificationId, code); |
| 58 | + } |
| 59 | +} |
0 commit comments