0

I am making a Whatsapp like app(By Following tutorial). It crashes when i click on send code button. i confirmed it by try/catch my phone number verification is not working or there's a problem with it

java.lang.IllegalArgumentException: Cannot create PhoneAuthCredential 
without either verificationProof, sessionInfo, ortemprary proof.

What i confirmed/tried: both activities are declared in manifest, assigned id to layout, initialized relative argument, Nothing is there in libs folder of the project, swapped initialization with layout , Tried this code to get value:

    String.valueOf(phoneNumberEdt)

I did all what i could as per my level

public class MainActivity extends AppCompatActivity {
    private EditText phoneNumberEdt, verificationcodeEdt;
    Button sendCodeButton;

private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallBacks;

String mVerificationId = "0";

//private PhoneAuthProvider.ForceResendingToken mResendToken;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    phoneNumberEdt = (EditText) findViewById(R.id.phonenumber_edt);
    verificationcodeEdt = (EditText) 
findViewById(R.id.verificationcode_edt);
    sendCodeButton = (Button) findViewById(R.id.sendcode_btn);

    FirebaseApp.initializeApp(this);

    userIsLoggedIn();
    phoneNumberEdt.setText("03026989523");
    sendCodeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //try{
            if(mVerificationId != null)
                verifyPhoneNumberWithCode();
            else
                startPhoneNumberVerification();
            /*}catch (Exception e){
                Toast toast = Toast.makeText(getApplicationContext(),  
"Verification Code is wrong, try again", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER,0,0);
                toast.show();
            }*/


            mCallBacks = new 
PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
                @Override
                public void onVerificationCompleted(PhoneAuthCredential 
phoneAuthCredential) {

                    signInWithPhoneAuthCredential(phoneAuthCredential);
                }

                @Override
                public void onVerificationFailed(FirebaseException e) {}

                @Override
                public void onCodeSent(String VerificationId, 
PhoneAuthProvider.ForceResendingToken forceResendingToken) {
                    super.onCodeSent(VerificationId, forceResendingToken);
                     mVerificationId = VerificationId;
                     sendCodeButton.setText("Verify Code");
                }

            };
        }
    });
 }

Error points here

private void startPhoneNumberVerification() {

    PhoneAuthProvider.getInstance().verifyPhoneNumber(

phoneNumberEdt.getText().toString(),//String.valueOf(phoneNumberEdt)
             60,
            TimeUnit.SECONDS,
            this,
            mCallBacks);
 }

Rest of the functions

private void verifyPhoneNumberWithCode(){
      PhoneAuthCredential credential = 
PhoneAuthProvider.getCredential(mVerificationId, 
verificationcodeEdt.getText().toString());
    signInWithPhoneAuthCredential(credential);
}

private void signInWithPhoneAuthCredential(PhoneAuthCredential 
phoneAuthCredential) {



FirebaseAuth.getInstance().signInWithCredential(phoneAuthCredential).
addOnComp leteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
                 if(task.isSuccessful())
                     userIsLoggedIn();
        }
    });

 }

 private void userIsLoggedIn() {

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if(user != null) {
        startActivity(new 
  Intent(getApplicationContext(),MainPageActivity.class));
        finish();
        return;
    }

  }
Kaleem
  • 129
  • 1
  • 14

0 Answers0