当前位置: 首页>>代码示例>>Java>>正文


Java PhoneAuthProvider.OnVerificationStateChangedCallbacks方法代码示例

本文整理汇总了Java中com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks方法的典型用法代码示例。如果您正苦于以下问题:Java PhoneAuthProvider.OnVerificationStateChangedCallbacks方法的具体用法?Java PhoneAuthProvider.OnVerificationStateChangedCallbacks怎么用?Java PhoneAuthProvider.OnVerificationStateChangedCallbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.firebase.auth.PhoneAuthProvider的用法示例。


在下文中一共展示了PhoneAuthProvider.OnVerificationStateChangedCallbacks方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: phoneNumberVerificationCB

import com.google.firebase.auth.PhoneAuthProvider; //导入方法依赖的package包/类
private void phoneNumberVerificationCB() {
    mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

        @Override
        public void onVerificationCompleted(PhoneAuthCredential credential) {
            Log.d(TAG, "onVerificationCompleted:" + credential);
            credent = credential;
        }

        @Override
        public void onVerificationFailed(FirebaseException e) {
            Log.w(TAG, "onVerificationFailed", e);

            if (e instanceof FirebaseAuthInvalidCredentialsException) {
                // Invalid request
                // ...
            } else if (e instanceof FirebaseTooManyRequestsException) {
                // The SMS quota for the project has been exceeded
                // ...
            }
        }
    };
}
 
开发者ID:kcj8855,项目名称:Ae4Team,代码行数:24,代码来源:ChangePhoneNumberActivity.java

示例2: testVerifyPhoneNumberNoMsgException_showsAlertDialog

import com.google.firebase.auth.PhoneAuthProvider; //导入方法依赖的package包/类
@Test
@Config(shadows = {AuthHelperShadow.class})
public void testVerifyPhoneNumberNoMsgException_showsAlertDialog() {
    reset(AuthHelperShadow.getPhoneAuthProvider());

    mActivity.verifyPhoneNumber(PHONE, false);
    verify(AuthHelperShadow.getPhoneAuthProvider()).verifyPhoneNumber(
            eq(PHONE),
            eq(AUTO_RETRIEVAL_TIMEOUT_MILLIS),
            eq(TimeUnit.MILLISECONDS),
            eq(mActivity),
            callbacksArgumentCaptor.capture(),
            (PhoneAuthProvider.ForceResendingToken) isNull());

    PhoneAuthProvider.OnVerificationStateChangedCallbacks onVerificationStateChangedCallbacks
            = callbacksArgumentCaptor.getValue();

    onVerificationStateChangedCallbacks.onVerificationFailed(
            new FirebaseAuthException("some_code", "custom_message"));
    assertTrue(mActivity.getAlertDialog().isShowing());
    assertEquals(FirebaseAuthError.ERROR_UNKNOWN.getDescription(), getAlertDialogMessage());
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:23,代码来源:PhoneActivityTest.java

示例3: testAutoVerify

import com.google.firebase.auth.PhoneAuthProvider; //导入方法依赖的package包/类
@Test
@Config(shadows = {AuthHelperShadow.class})
public void testAutoVerify() {
    reset(AuthHelperShadow.getPhoneAuthProvider());
    reset(AuthHelperShadow.getSaveSmartLockInstance(null));
    reset(AuthHelperShadow.getFirebaseAuth());

    when(AuthHelperShadow.getCurrentUser().getPhoneNumber()).thenReturn(PHONE);
    when(AuthHelperShadow.getCurrentUser().getEmail()).thenReturn(null);
    when(AuthHelperShadow.getFirebaseAuth().signInWithCredential(any(AuthCredential.class)))
            .thenReturn(new AutoCompleteTask<>(FakeAuthResult.INSTANCE, true, null));
    mActivity.verifyPhoneNumber(PHONE, false);
    verify(AuthHelperShadow.getPhoneAuthProvider()).verifyPhoneNumber(
            eq(PHONE),
            eq(AUTO_RETRIEVAL_TIMEOUT_MILLIS),
            eq(TimeUnit.MILLISECONDS),
            eq(mActivity),
            callbacksArgumentCaptor.capture(),
            (PhoneAuthProvider.ForceResendingToken) isNull());

    PhoneAuthProvider.OnVerificationStateChangedCallbacks onVerificationStateChangedCallbacks
            = callbacksArgumentCaptor.getValue();

    onVerificationStateChangedCallbacks.onVerificationCompleted(credential);
    verify(AuthHelperShadow.getFirebaseAuth()).signInWithCredential(any(AuthCredential.class));
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:27,代码来源:PhoneActivityTest.java

示例4: testSMSAutoRetrieval

import com.google.firebase.auth.PhoneAuthProvider; //导入方法依赖的package包/类
@Test
@Config(shadows = {AuthHelperShadow.class})
public void testSMSAutoRetrieval() {
    reset(AuthHelperShadow.getPhoneAuthProvider());
    reset(AuthHelperShadow.getSaveSmartLockInstance(null));
    when(credential.getSmsCode()).thenReturn("123456");

    when(AuthHelperShadow.getCurrentUser().getPhoneNumber()).thenReturn(PHONE);
    when(AuthHelperShadow.getCurrentUser().getEmail()).thenReturn(null);

    when(AuthHelperShadow.getFirebaseAuth().signInWithCredential(any(AuthCredential.class)))
            .thenReturn(new AutoCompleteTask<>(FakeAuthResult.INSTANCE, true, null));
    PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks =
            testSendConfirmationCode();
    callbacks.onVerificationCompleted(credential);
    SpacedEditText mConfirmationCodeEditText = mActivity.findViewById(R.id.confirmation_code);

    //verify confirmation code set
    assertEquals("1 2 3 4 5 6", mConfirmationCodeEditText.getText().toString());
    //verify credential saves
    verify(AuthHelperShadow.getFirebaseAuth()).signInWithCredential(credential);
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:23,代码来源:PhoneActivityTest.java

示例5: testVerifyPhoneNumberInvalidPhoneException_showsInlineError

import com.google.firebase.auth.PhoneAuthProvider; //导入方法依赖的package包/类
@Test
@Config(shadows = {AuthHelperShadow.class})
public void testVerifyPhoneNumberInvalidPhoneException_showsInlineError() {
    reset(AuthHelperShadow.getPhoneAuthProvider());

    mActivity.verifyPhoneNumber(PHONE, false);
    //was dialog displayed
    assertEquals(
            mActivity.getString(R.string.fui_verifying),
            mActivity.mProgressDialog.mMessageView.getText());

    //was upstream method invoked
    verify(AuthHelperShadow.getPhoneAuthProvider()).verifyPhoneNumber(
            eq(PHONE),
            eq(AUTO_RETRIEVAL_TIMEOUT_MILLIS),
            eq(TimeUnit.MILLISECONDS),
            eq(mActivity),
            callbacksArgumentCaptor.capture(),
            (PhoneAuthProvider.ForceResendingToken) isNull());

    PhoneAuthProvider.OnVerificationStateChangedCallbacks onVerificationStateChangedCallbacks
            = callbacksArgumentCaptor.getValue();
    onVerificationStateChangedCallbacks.onVerificationFailed(
            new FirebaseAuthException(
                    FirebaseAuthError.ERROR_INVALID_PHONE_NUMBER.toString(),
                    "any_message"));

    //was error displayed
    assertEquals(mPhoneLayout.getError(), mActivity.getString(R.string.fui_invalid_phone_number));
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:31,代码来源:PhoneActivityTest.java

示例6: testSendConfirmationCode

import com.google.firebase.auth.PhoneAuthProvider; //导入方法依赖的package包/类
private PhoneAuthProvider.OnVerificationStateChangedCallbacks testSendConfirmationCode() {
    mActivity.verifyPhoneNumber(PHONE, false);
    verify(AuthHelperShadow.getPhoneAuthProvider()).verifyPhoneNumber(
            eq(PHONE),
            eq(AUTO_RETRIEVAL_TIMEOUT_MILLIS),
            eq(TimeUnit.MILLISECONDS),
            eq(mActivity),
            callbacksArgumentCaptor.capture(),
            (PhoneAuthProvider.ForceResendingToken) isNull());

    PhoneAuthProvider.OnVerificationStateChangedCallbacks onVerificationStateChangedCallbacks
            = callbacksArgumentCaptor.getValue();

    onVerificationStateChangedCallbacks.onCodeSent(verificationId, forceResendingToken);

    //Force postDelayed runnables to completed on looper
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

    SubmitConfirmationCodeFragment fragment = (SubmitConfirmationCodeFragment) mActivity
            .getSupportFragmentManager().findFragmentByTag(SubmitConfirmationCodeFragment.TAG);
    assertNotNull(fragment);

    SpacedEditText mConfirmationCodeEditText = mActivity
            .findViewById(R.id.confirmation_code);
    assertTrue(mConfirmationCodeEditText.isFocused());

    return onVerificationStateChangedCallbacks;
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:29,代码来源:PhoneActivityTest.java

示例7: onCreate

import com.google.firebase.auth.PhoneAuthProvider; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {

    PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_otp);


    sentNumber="INVALID";

    //Check for the OTP
    mCallbacks=new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
        @Override
        public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
            sentNumber=phoneAuthCredential.getSmsCode();
            Toasty.success(OTP.this, "Verification Success", Toast.LENGTH_SHORT).show();
            moveToNextActivity();
        }

        @Override
        public void onVerificationFailed(FirebaseException e) {

            Toasty.error(OTP.this, "Invalid OTP", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCodeSent(String verificationId,
                               PhoneAuthProvider.ForceResendingToken token) {
            // Log.d(TAG, "onCodeSent:" + verificationId);
            Toasty.info(OTP.this, "OTP has been send to your number", Toast.LENGTH_SHORT).show();
            // Save verification ID and resending token so we can use them later
            mVerificationId = verificationId;
            mResendToken = token;
        }
    };

    //Phone Auth Parameters
    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            LocalDB.getPhoneNumber(),
            60,
            java.util.concurrent.TimeUnit.SECONDS,
            OTP.this,
            mCallbacks);


    if(!isNetworkAvailable())
    {
        Toasty.warning(OTP.this,"Please Check Your Internet Connection and Try Again", Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:Nihal369,项目名称:Amaro,代码行数:52,代码来源:OTP.java

示例8: verifyPhoneNumber

import com.google.firebase.auth.PhoneAuthProvider; //导入方法依赖的package包/类
private void verifyPhoneNumber(String phoneNumber){

        if (!isValid){
            Toast.makeText(this, "Invalid Phone number!", Toast.LENGTH_SHORT).show();
            return;
        }

        hud.show();
        mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

            @Override
            public void onVerificationCompleted(PhoneAuthCredential credential) {
                // This callback will be invoked in two situations:
                // 1 - Instant verification. In some cases the phone number can be instantly
                //     verified without needing to send or enter a verification code.
                // 2 - Auto-retrieval. On some devices Google Play services can automatically
                //     detect the incoming verification SMS and perform verification without
                //     user action.
                Log.d(TAG, "onVerificationCompleted:" + credential);

                hud.dismiss();

                signInWithPhoneAuthCredential(credential);
            }

            @Override
            public void onVerificationFailed(FirebaseException e) {
                // This callback is invoked in an invalid request for verification is made,
                // for instance if the the phone number format is not valid.
                Toast.makeText(RegisterPhoneActivity.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();

                if (e instanceof FirebaseAuthInvalidCredentialsException) {
                    // Invalid request
                    Toast.makeText(RegisterPhoneActivity.this, "Invalid mobile number", Toast.LENGTH_SHORT).show();
                } else if (e instanceof FirebaseTooManyRequestsException) {
                    // The SMS quota for the project has been exceeded
                    Toast.makeText(RegisterPhoneActivity.this, "The SMS quota for the project has been exceeded", Toast.LENGTH_SHORT).show();
                }

                // Show a message and update the UI

                hud.dismiss();
            }

            @Override
            public void onCodeSent(String verificationId,
                                   PhoneAuthProvider.ForceResendingToken token) {
                // The SMS verification code has been sent to the provided phone number, we
                // now need to ask the user to enter the code and then construct a credential
                // by combining the code with a verification ID.
                Log.d(TAG, "onCodeSent:" + verificationId);

                // Save verification ID and resending token so we can use them later
                phoneVerficationID = verificationId;
                resendToken = token;
                Toast.makeText(RegisterPhoneActivity.this, getString(R.string.register_verify_sent), Toast.LENGTH_SHORT).show();
                hud.dismiss();

                startResendTimer();
            }
        };

        PhoneAuthProvider.getInstance().verifyPhoneNumber(
                phoneNumber,
                60,
                TimeUnit.SECONDS,
                this,
                mCallbacks);

    }
 
开发者ID:AppHero2,项目名称:Raffler-Android,代码行数:71,代码来源:RegisterPhoneActivity.java


注:本文中的com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。