使用Firebase进行身份验证时出现java.lang.IllegalArgumentException

时间:2019-04-25 05:43:39

标签: android firebase firebase-authentication whatsapp illegalargumentexception

我正在制作类似Whatsapp的应用程序(通过下面的教程)。当我点击发送代码按钮时,它会崩溃。我通过尝试/捕获来确认我的电话号码验证不起作用或有问题

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

我确认/尝试过的内容: 这两个活动都在清单中声明, 为布局分配了ID, 已初始化相对论点, 项目的 libs文件夹中没有任何内容, 通过布局交换进行初始化, 尝试使用此代码来获取价值:

    String.valueOf(phoneNumberEdt)

我已尽我所能

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");
                }

            };
        }
    });
 }

错误点在这里

private void startPhoneNumberVerification() {

    PhoneAuthProvider.getInstance().verifyPhoneNumber(

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

其余功能

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;
    }

  }

0 个答案:

没有答案