我正在尝试为多个设备测试firebase phone auth,当我尝试使用Android 5.0或更高版本的手机时,它运行正常。对于较低的android api,我收到此消息:
此应用无权使用Firebase身份验证。请确认在Firebase控制台中配置了正确的软件包名称和SHA-1。 [应用验证失败。应用是否在物理设备上运行? ]
这是我的手机验证栏
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
// This callback will be invoked in two situations:
// 1 - Instant verification. In some cases the phone number can be instantly
// verified without needing to send or enter a verification code.
// 2 - Auto-retrieval. On some devices Google Play services can automatically
// detect the incoming verification SMS and perform verificaiton without
// user action.
Log.d(TAG, "onVerificationCompleted:" + credential);
Snackbar.make(findViewById(android.R.id.content), "Verification completed.",
Snackbar.LENGTH_SHORT).show();
spinner.setVisibility(View.GONE);
// [START_EXCLUDE silenst]
mVerificationInProgress = false;
// [END_EXCLUDE]
// [START_EXCLUDE silent]
// Update the UI and attempt sign in with the phone credential
//updateUI(STATE_VERIFY_SUCCESS, credential);
// [END_EXCLUDE]
//signInWithPhoneAuthCredential(credential);
deviceTokenCheck(phoneNumber);
}
@Override
public void onVerificationFailed(FirebaseException e) {
// This callback is invoked in an invalid request for verification is made,
// for instance if the the phone number format is not valid.
Log.w(TAG, "onVerificationFailed", e);
// [START_EXCLUDE silent]
mVerificationInProgress = false;
// [END_EXCLUDE]
spinner.setVisibility(View.GONE);
if (e instanceof FirebaseAuthInvalidCredentialsException) {
// Invalid request
// [START_EXCLUDE]
mPhoneNumberField.setError("Invalid phone number.");
// [END_EXCLUDE]
} else if (e instanceof FirebaseTooManyRequestsException) {
// The SMS quota for the project has been exceeded
// [START_EXCLUDE]
Snackbar.make(findViewById(android.R.id.content), "Quota exceeded.",
Snackbar.LENGTH_SHORT).show();
// [END_EXCLUDE]
}
// Show a message and update the UI
// [START_EXCLUDE]
updateUI(STATE_VERIFY_FAILED);
// [END_EXCLUDE]
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
// The SMS verification code has been sent to the provided phone number, we
// now need to ask the user to enter the code and then construct a credential
// by combining the code with a verification ID.
Log.d(TAG, "onCodeSent:" + verificationId);
spinner.setVisibility(View.GONE);
Snackbar.make(findViewById(android.R.id.content), "Code Sent.",
Snackbar.LENGTH_SHORT).show();
// Save verification ID and resending token so we can use them later
mVerificationId = verificationId;
mResendToken = token;
// [START_EXCLUDE]
// Update UI
updateUI(STATE_CODE_SENT);
// [END_EXCLUDE]
}
};
// [END phone_auth_callbacks]
}