Я делаю простое приложение для аутентификации пользователя по номеру телефона. Я получил код от здесь я сделал все правильно, сколько смогу, но я получаю сообщение об ошибке, как показано ниже, я не знаю, в чем причина этой ошибки, пожалуйста, помогите мне, я действительно хочу сделать это ap
2019-03-10 07:10:03.570 12764-12764/com.example.meenvandi E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.meenvandi, PID: 12764
java.lang.IllegalArgumentException: Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, ortemprary proof.
at com.google.android.gms.common.internal.Preconditions.checkArgument(Unknown Source:35)
at com.google.firebase.auth.PhoneAuthCredential.<init>(Unknown Source:6)
at com.google.firebase.auth.PhoneAuthProvider.getCredential(Unknown Source:33)
at com.example.meenvandi.VerifyPhoneActivity.verifyVerificationCode(VerifyPhoneActivity.java:158)
at com.example.meenvandi.VerifyPhoneActivity.access$000(VerifyPhoneActivity.java:25)
at com.example.meenvandi.VerifyPhoneActivity$2.onVerificationCompleted(VerifyPhoneActivity.java:137)
at com.google.firebase.auth.api.internal.zzer.zza(Unknown Source:2)
at com.google.firebase.auth.api.internal.zzeu.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:192)
at android.app.ActivityThread.main(ActivityThread.java:6778)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:875)
это мой код такой же, как и по ссылке, небольшие изменения
public class VerifyPhoneActivity extends AppCompatActivity {
//These are the objects needed
//It is the verification id that will be sent to the user
private String mVerificationId;
//The edittext to input the code
private EditText editTextCode;
//firebase auth object
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_verify_phone);
FirebaseApp.initializeApp(getApplicationContext());
//initializing objects
mAuth = FirebaseAuth.getInstance();
//getting mobile number from the previous activity
//and sending the verification code to the number
Intent intent = getIntent();
String mobile = intent.getStringExtra("mobile");
sendVerificationCode(mobile);
//if the automatic sms detection did not work, user can also enter the code manually
//so adding a click listener to the button
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText fd = (EditText) findViewById(R.id.et1);
String value= fd.getText().toString();
// int finalValue=Integer.parseInt(value);
final EditText sd = (EditText) findViewById(R.id.et2);
String value1= sd.getText().toString();
// int finalValue1=Integer.parseInt(value1);
EditText td = (EditText) findViewById(R.id.et3);
String value2= td.getText().toString();
// int finalValue2=Integer.parseInt(value2);
EditText fod = (EditText) findViewById(R.id.et4);
String value3= fod.getText().toString();
//int finalValue3=Integer.parseInt(value3);
EditText fid = (EditText) findViewById(R.id.et5);
String value4= fid.getText().toString();
//int finalValue4=Integer.parseInt(value4);
EditText sid = (EditText) findViewById(R.id.et6);
String value5= sid.getText().toString();
//int finalValue5=Integer.parseInt(value5);
String code = value + value1+value2+value3+value4+value5;
// String code = editTextCode.getText().toString().trim();
// if (code.isEmpty() || code.length() < 6) {
// editTextCode.setError("Enter valid code");
// editTextCode.requestFocus();
// return;
// }
//verifying the code entered manually
verifyVerificationCode(code);
}
});
}
//the method is sending verification code
//the country id is concatenated
//you can take the country id as user input as well
private void sendVerificationCode(String mobile) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
"+91" + mobile,
60,
TimeUnit.SECONDS,
TaskExecutors.MAIN_THREAD,
mCallbacks);
}
//the callback to detect the verification status
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
//Getting the code sent by SMS
String code = phoneAuthCredential.getSmsCode();
//sometime the code is not detected automatically
//in this case the code will be null
//so user has to manually enter the code
// if (code != null) {
// editTextCode.setText(code);
//verifying the code
verifyVerificationCode(code);
//}
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(VerifyPhoneActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
//storing the verification id that is sent to the user
mVerificationId = s;
}
};
private void verifyVerificationCode(String code) {
//creating the credential
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, code);
//signing the user
signInWithPhoneAuthCredential(credential);
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(VerifyPhoneActivity.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(VerifyPhoneActivity.this, ProfileActivity.class);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
// startActivity(intent);
Snackbar snackbar = Snackbar.make(findViewById(R.id.parent), "sucess", Snackbar.LENGTH_LONG);
} else {
//verification unsuccessful.. display an error message
String message = "Somthing is wrong, we will fix it soon...";
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
message = "Invalid code entered...";
}
Snackbar snackbar = Snackbar.make(findViewById(R.id.parent), message, Snackbar.LENGTH_LONG);
snackbar.setAction("Dismiss", new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
snackbar.show();
}
}
});
}
}