在android studio中使用firebase进行手机身份验证时,在我的荣誉手机中单击“自动填充”后,键盘未弹出

在android studio中使用firebase进行手机身份验证时,在我的荣誉手机中单击“自动填充”后,键盘未弹出,android,firebase,android-studio,firebase-authentication,Android,Firebase,Android Studio,Firebase Authentication,我正在尝试使用firebase在android中实现电话身份验证。在这里,当我尝试通过其他人的手机号码登录时,当我点击editText时,它会显示“自动填充来自消息的代码”。如果我单击“自动填充”,它将停止显示键盘,并且在我连续点击该编辑文本后,它甚至不会将键盘调到enter键。请帮忙。以下是相关代码: public class otpVerification extends AppCompatActivity { private String mVerificationId; private

我正在尝试使用firebase在android中实现电话身份验证。在这里,当我尝试通过其他人的手机号码登录时,当我点击editText时,它会显示“自动填充来自消息的代码”。如果我单击“自动填充”,它将停止显示键盘,并且在我连续点击该编辑文本后,它甚至不会将键盘调到enter键。请帮忙。以下是相关代码:

public class otpVerification extends AppCompatActivity {

private String mVerificationId;
private FirebaseAuth mAuth;
private ProgressBar progressBar;
private TextView resend;
private EditText editText;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_otp_verification);
    mAuth = FirebaseAuth.getInstance();
    progressBar = (findViewById(R.id.progressbar));
    editText = (findViewById(R.id.editTextCode));
    resend = findViewById(R.id.resend);

    final String mobile = getIntent().getStringExtra("mobile");

    sendVerificationCode(mobile);
    findViewById(R.id.buttonSignIn).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String code = editText.getText().toString();
            if (code.isEmpty() || code.length() < 6) {
                progressBar.setVisibility(View.INVISIBLE);
                editText.setEnabled(true);
                editText.setError("Enter code manually");
                editText.requestFocus();
                return;
            } else if (code.replace(" ", "").length() != 6) {
                progressBar.setVisibility(View.INVISIBLE);
                Toast.makeText(otpVerification.this, "Enter correct OTP", Toast.LENGTH_SHORT).show();
            } else {
                //verifying the code
                verifyVerificationCode(code);
            }
        }
    });

    resend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            sendVerificationCode(mobile);
        }
    });
}

private void verifyVerificationCode(String otp) {

    progressBar.setVisibility(View.VISIBLE);
    PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, otp);
    signInWithPhoneAuthCredential(credential);
}

private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(otpVerification.this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {

                        //verification successful we will start the profile activity
                        Intent intent = new Intent(otpVerification.this, MainActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                        finish();

                    } else {
                        Toast.makeText(otpVerification.this, "Verification failed", Toast.LENGTH_SHORT).show();
                    }
                }
            });
}

private void sendVerificationCode(String mobile) {
    progressBar.setVisibility(View.VISIBLE);

    new CountDownTimer(30000, 1000) {
        @Override
        public void onTick(long l) {
            resend.setText("" + l / 1000);
            resend.setEnabled(false);
            editText.setEnabled(true);
        }

        @Override
        public void onFinish() {
            progressBar.setVisibility(View.INVISIBLE);
            resend.setText(" Resend");
            resend.setEnabled(true);
            editText.setEnabled(true);
        }
    }.start();

    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            "+91" + mobile,
            60,
            TimeUnit.SECONDS,
            TaskExecutors.MAIN_THREAD,
            mCallbacks);
}

private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

    @Override
    public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
        super.onCodeSent(s, forceResendingToken);
        mVerificationId = s;
    }

    @Override
    public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
        String code = phoneAuthCredential.getSmsCode();
        if (code != null) {
            editText.setText(code);
            verifyVerificationCode(code);
        }
    }

    @Override
    public void onVerificationFailed(@NonNull FirebaseException e) {
        Toast.makeText(otpVerification.this, e.getMessage(), Toast.LENGTH_LONG).show();
    }
};
}
公共类OTP验证扩展了AppCompative活动{
私有字符串mvericationid;
私人消防队;
私人ProgressBar ProgressBar;
私有文本视图重发;
私人编辑文本;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u otp\u验证);
mAuth=FirebaseAuth.getInstance();
progressBar=(findViewById(R.id.progressBar));
editText=(findViewById(R.id.editTextCode));
重发=findViewById(R.id.resend);
最终字符串mobile=getIntent().getStringExtra(“mobile”);
发送验证码(移动);
findViewById(R.id.buttonSignIn).setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
字符串代码=editText.getText().toString();
if(code.isEmpty()| code.length()<6){
progressBar.setVisibility(View.INVISIBLE);
editText.setEnabled(true);
editText.setError(“手动输入代码”);
editText.requestFocus();
返回;
}else if(code.replace(“,”).length()!=6){
progressBar.setVisibility(View.INVISIBLE);
Toast.makeText(otpVerification.this,“输入正确的OTP”,Toast.LENGTH_SHORT.show();
}否则{
//验证代码
验证代码(代码);
}
}
});
resend.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
发送验证码(移动);
}
});
}
专用无效验证代码(字符串otp){
progressBar.setVisibility(View.VISIBLE);
PhoneAuthCredential credential=PhoneAuthProvider.getCredential(mvericationId,otp);
使用PhoneAuthCredential(凭证)登录;
}
使用PhoneAuthCredential(PhoneAuthCredential凭据)的专用无效登录{
mAuth.SIGNWITH凭证(凭证)
.addOnCompleteListener(otpVerification.this,新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
//验证成功,我们将启动配置文件活动
意向意向=新意向(otpVerification.this,MainActivity.class);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_CLEAR_TASK);
星触觉(意向);
完成();
}否则{
Toast.makeText(otpVerification.this,“验证失败”,Toast.LENGTH_SHORT.show();
}
}
});
}
私有void sendVerificationCode(字符串移动){
progressBar.setVisibility(View.VISIBLE);
新的倒计时(300001000){
@凌驾
公共空白条(长l){
重新发送。设置文本(“+l/1000);
resend.setEnabled(错误);
editText.setEnabled(true);
}
@凌驾
公共无效onFinish(){
progressBar.setVisibility(View.INVISIBLE);
重新发送。设置文本(“重新发送”);
ressend.setEnabled(true);
editText.setEnabled(true);
}
}.start();
PhoneAuthProvider.getInstance().verifyPhoneNumber(
“+91”+移动电话,
60,
时间单位:秒,
TaskExecutors.MAIN_线程,
mCallbacks);
}
私有PhoneAuthProvider.OnVerificationStateChangedCallbacks McCallbacks=新PhoneAuthProvider.OnVerificationStateChangedCallbacks(){
@凌驾
public void onCodeSent(字符串s,PhoneAuthProvider.ForceResendingToken ForceResendingToken){
超级OnCondent(s,forceResendingToken);
mvericationid=s;
}
@凌驾
public void onVerificationCompleted(@NonNull PhoneAuthCredential PhoneAuthCredential){
字符串代码=phoneAuthCredential.getSmsCode();
如果(代码!=null){
editText.setText(代码);
验证代码(代码);
}
}
@凌驾
public void onVerificationFailed(@NonNull FirebaseException e){
Toast.makeText(otpVerification.this,e.getMessage(),Toast.LENGTH_LONG.show();
}
};
}

我不确定您的情况,但有一次我遇到了同样的情况,那是因为我在底部显示编辑的文本,这在某种程度上限制了键盘弹出。嗨,Waqas,我将编辑文本稍微向上放,以便键盘可以轻松弹出。事实上,在各种设备中,它工作正常,但在荣誉手机中,它却在制造问题。如果你知道或者我在代码中写错了什么,请帮助。有没有什么像我们可以在任何UI中禁用“从消息自动填充代码选项”这样的东西?我不确定你的情况,但有一次我遇到了同样的事情,那是因为我在底部显示编辑过的文本,这在某种程度上限制了键盘弹出。嗨,Waqas,我把我的编辑文本稍微向上放,这样键盘就可以很容易地弹出。事实上,在各种设备中,它工作正常,但在荣誉手机中,它却在制造问题。如果您知道或者我在代码中写错了什么,请提供帮助。我们是否可以在任何UI中禁用“从消息自动填充代码”选项?