简体   繁体   English

如何使用 java android 在 firebase 中发送 otp 代码短信?

[英]How to send otp code sms in firebase with java android?

I have a Android Studio project with firebase, I already implement firebase correctly.我有一个带有 firebase 的 Android Studio 项目,我已经正确实现了 firebase。

im trying to make a sign in with sms authentication, everything works but no sms arrives我正在尝试使用短信身份验证登录,一切正常但没有短信到达在此处输入图像描述

I already configure firebase authentication我已经配置了firebase认证

here's some code这是一些代码

mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
                @Override
                public void onVerificationCompleted(PhoneAuthCredential credential) {
                    Toast.makeText(MainActivity.this, "Verification Complete", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onVerificationFailed(FirebaseException e) {
                    Toast.makeText(MainActivity.this, "Verification Failed", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onCodeSent(String verificationId,
                                       PhoneAuthProvider.ForceResendingToken token) {
                    Toast.makeText(MainActivity.this, "Code Sent", Toast.LENGTH_SHORT).show();
                }
            };
@Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_send_otp:

                PhoneAuthProvider.getInstance().verifyPhoneNumber(
                        etPhone.getText().toString(),        // Phone number to verify
                        1,                 // Timeout duration
                        TimeUnit.MINUTES,   // Unit of timeout
                        this,               // Activity (for callback binding)
                        mCallbacks);        // OnVerificationStateChangedCallbacks

                break;
            case R.id.bt_resend_otp:
                break;
            case R.id.bt_verify_otp:
                break;
        }
   }

when I press the send otp button the toast "Code Sent" appears当我按下发送 otp 按钮时,吐司“代码已发送”出现

Thanks for the help:)谢谢您的帮助:)

Since it is a test number, OTP will not arrive.由于是测试号, OTP不会到达。 Though for testing you can use the verification code you added with the test phone number on the console.虽然对于测试,您可以使用您添加的验证码和控制台上的测试电话号码。 Firebase Console Dashboard -> Authentication -> SignIn Method -> Phone -> Phone numbers for testing . Firebase Console Dashboard -> Authentication -> SignIn Method -> Phone -> Phone numbers for testing

在此处输入图像描述

Check out the docs for Firebase Phone Verification for Android : https://firebase.google.com/docs/auth/android/phone-auth?authuser=1#test-with-whitelisted-phone-numbers查看Firebase Phone Verification Android的文档: https://firebase.google.com/thphoneuser-number1#test?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM