I am using Red-mi note 5 pro MIUI version 11.0.3 i am using with Auto Read otp from Firebase but that otp is not entering automatically in my mobile. But its automatic getting every android mobile also even in MIUI versions 11.0.2,11.0.4,11.0.8 ( Samsung,one plus, etc..)
Please help me to find out the solution for this problem.
private void signInWithCredential(PhoneAuthCredential credential) {
Log.d("getsms","sign credential");
firebaseAuth.signInWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d("getsms", "completed0");
System.out.println("otpmobilenumber " + mobilenumber);
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
Const.UUID = user.getUid();
Log.d("UUIdd ", "uid no" + Const.UUID);
if (user.getUid() == null) {
Log.d("currentuid ", "failure");
Log.d("getsms", "uid no null");
} else if (user.getUid() != null) {
Log.d("getsms", "uid no" + Const.UUID);
Log.d("getsms", "userexists" + Const.UserExists);
callIntent();
}
}
});
}
private void sendVerificationCode(String phonenumber) {
Log.d("getsms","phoneNumber "+phonenumber);
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phonenumber,
60,
TimeUnit.SECONDS,
OtpActivity.this,
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
Log.d("getsms","code "+phoneAuthCredential.getSmsCode());
mobileotp=phoneAuthCredential.getSmsCode();
mobileotp = phoneAuthCredential.getSmsCode();
if (mobileotp != null) {
char[] chars = mobileotp.toCharArray();
System.out.println("charrrsss" + chars);
String c1 = String.valueOf(mobileotp.charAt(0));
String c2 = String.valueOf(mobileotp.charAt(1));
String c3 = String.valueOf(mobileotp.charAt(2));
String c4 = String.valueOf(mobileotp.charAt(3));
String c5 = String.valueOf(mobileotp.charAt(4));
String c6 = String.valueOf(mobileotp.charAt(5));
one.setText(c1);
two.setText(c2);
three.setText(c3);
four.setText(c4);
five.setText(c5);
six.setText(c6);
otpcode.setText(mobileotp);
/* otpcode.setOnCompleteListener(new com.broooapps.otpedittext2.OnCompleteListener() {
@Override
public void onComplete(String value) {
otpcode.setText(value);
}
});*/
Log.d("getsms", "call verifyCode");
verifyCode(mobileotp);
//otpcode.setText(mobileotp);
} else {
Toast.makeText(getApplicationContext(),"Enter The Otp",Toast.LENGTH_SHORT).show();
//otpcode.setError("Enter The OTP");
}
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
Log.d("getsms","code fail "+e.getMessage());
}
@Override
public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verificationid=s;
Log.d("getsms","verify code "+s);
}
}
);
}