【问题标题】:How to change resend OTP time in Phone Number Authentication by FirebaseUI如何通过 FirebaseUI 在电话号码身份验证中更改重新发送 OTP 时间
【发布时间】:2017-09-09 08:59:23
【问题描述】:

我正在使用 FirebaseUI 在我的应用中创建电话号码身份验证活动。缺省情况下,重发 OPT 的时间为 15 秒。我想改变这个时间限制。该怎么做?

public class PhoneNumberAuthentication extends AppCompatActivity {
    private static final int RC_SIGN_IN = 123;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FirebaseAuth auth = FirebaseAuth.getInstance();
        if (auth.getCurrentUser() != null) {
            // already signed in
            startActivity(new Intent(PhoneNumberAuthentication.this, MainActivity.class));
            finish();
        } else {
            // not signed in
            startActivityForResult(
                    AuthUI.getInstance()
                            .createSignInIntentBuilder()
                            .setAvailableProviders(
                                    Arrays.asList(
                                            new AuthUI.IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER).build()
                                            ))
                            .build(),
                    RC_SIGN_IN);
        }
    }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // RC_SIGN_IN is the request code you passed into startActivityForResult(...) when starting the sign in flow.
        if (requestCode == RC_SIGN_IN) {
            IdpResponse response = IdpResponse.fromResultIntent(data);
            // Successfully signed in
            if (resultCode == ResultCodes.OK) {
                startActivity(new Intent(PhoneNumberAuthentication.this,MainActivity.class));
                finish();
                return;
            } else {
                // Sign in failed
                if (response == null) {
                    // User pressed back button
                    Log.e("Login","Login canceled by User");
                    return;
                }
                if (response.getErrorCode() == ErrorCodes.NO_NETWORK) {
                    Log.e("Login","No Internet Connection");
                    return;
                }
                if (response.getErrorCode() == ErrorCodes.UNKNOWN_ERROR) {
                    Log.e("Login","Unknown Error");
                    return;
                }
            }
            Log.e("Login","Unknown sign in response");
        }
    }
}

我已附上 OPT 验证活动的屏幕截图:OTP Verification Activity。重新发送代码计时器从 15 开始倒计时,当它到达 0 时,它启用重新发送 OTP 按钮。我需要增加这个倒计时时间。

【问题讨论】:

  • 得到了任何答案。提供的那个不起作用。

标签: android authentication firebase firebaseui


【解决方案1】:

如果您只想根据时间启用或禁用重新发送 OTP 按钮,您可以使用处理程序作为

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                otpButton.setEnable(true);
            }
        }, 60000);

这会给你 60 秒的时间

【讨论】:

  • 谢谢.. 但是我应该把这个块放在我的代码哪里?
  • 当firebasebse phoneauth otp代码发送并且你去otp获取活动然后在onStart方法中
  • @UttamMeerwal 我知道这已经很晚了,OP 和任何使用 FirebaseUI Auth 库的开发人员都希望构建器类中的一个方法可以更改默认的重新发送 SMS 持续时间,即此时写作是没有的。
猜你喜欢
  • 2020-07-22
  • 2019-06-11
  • 1970-01-01
  • 1970-01-01
  • 2019-12-04
  • 1970-01-01
  • 2021-10-02
  • 1970-01-01
  • 2020-07-12
相关资源
最近更新 更多