尝试在模拟器和设备上注册时,我一直收到此错误。
身份验证failed.com.google.firebase.FirebaseException:发生了内部错误。 [OPERATION_NOT_ALLOWED]
我已经在控制台中的身份验证提供程序下启用了电子邮件,就像在另一个问题中提到的那样,但我仍然遇到问题。有任何想法吗? 我将播放服务依赖项设置为高于9.0.0,并且模拟器和我的测试设备都满足此要求
这是我的SignupActivity
代码
public class SignupActivity extends AppCompatActivity {
private static final String TAG = "SignupActivity" ;
private Button btnSignUp,btnLinkToLogIn;
private ProgressBar progressBar;
private FirebaseAuth auth;
private EditText signupInputEmail, signupInputPassword;
private TextInputLayout signupInputLayoutEmail, signupInputLayoutPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
auth = FirebaseAuth.getInstance();
signupInputLayoutEmail = (TextInputLayout) findViewById(R.id.signup_input_layout_email);
signupInputLayoutPassword = (TextInputLayout) findViewById(R.id.signup_input_layout_password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
signupInputEmail = (EditText) findViewById(R.id.signup_input_email);
signupInputPassword = (EditText) findViewById(R.id.signup_input_password);
btnSignUp = (Button) findViewById(R.id.btn_signup);
btnLinkToLogIn = (Button) findViewById(R.id.btn_link_login);
btnSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
submitForm();
}
});
btnLinkToLogIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(SignupActivity.this, LoginActivity.class);
startActivity(intent);
}
});
}
/**
* Validating form
*/
private void submitForm() {
String email = signupInputEmail.getText().toString().trim();
String password = signupInputPassword.getText().toString().trim();
if(!checkEmail()) {
return;
}
if(!checkPassword()) {
return;
}
signupInputLayoutEmail.setErrorEnabled(false);
signupInputLayoutPassword.setErrorEnabled(false);
progressBar.setVisibility(View.VISIBLE);
//create user
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(SignupActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG,"createUserWithEmail:onComplete:" + task.isSuccessful());
progressBar.setVisibility(View.GONE);
if (!task.isSuccessful()) {
Log.d(TAG,"Authentication failed." + task.getException());
} else {
startActivity(new Intent(SignupActivity.this, UserActivity.class));
finish();
}
}
});
Toast.makeText(getApplicationContext(), "You are successfully Registered !!", Toast.LENGTH_SHORT).show();
}
private boolean checkEmail() {
String email = signupInputEmail.getText().toString().trim();
if (email.isEmpty() || !isEmailValid(email)) {
signupInputLayoutEmail.setErrorEnabled(true);
signupInputLayoutEmail.setError(getString(R.string.err_msg_email));
signupInputEmail.setError(getString(R.string.err_msg_required));
requestFocus(signupInputEmail);
return false;
}
signupInputLayoutEmail.setErrorEnabled(false);
return true;
}
private boolean checkPassword() {
String password = signupInputPassword.getText().toString().trim();
if (password.isEmpty() || !isPasswordValid(password)) {
signupInputLayoutPassword.setError(getString(R.string.err_msg_password));
signupInputPassword.setError(getString(R.string.err_msg_required));
requestFocus(signupInputPassword);
return false;
}
signupInputLayoutPassword.setErrorEnabled(false);
return true;
}
private static boolean isEmailValid(String email) {
return !TextUtils.isEmpty(email) && android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
private static boolean isPasswordValid(String password){
return (password.length() >= 6);
}
private void requestFocus(View view) {
if (view.requestFocus()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
@Override
protected void onResume() {
super.onResume();
progressBar.setVisibility(View.GONE);
}
}
答案 0 :(得分:0)
请检查控制台Firebase中是否启用了身份验证方法。 如果您未启用Google身份验证,则只会在没有[OPERATION_NOT_ALLOWED]的情况下获得相同的异常。
有关详细信息,您可以在论坛帖子https://groups.google.com/forum/#!topic/firebase-talk/JTaIlD-tNxw
中查看解决方案请查看Firebase Auth 文档以获取更多信息。
我有同样的问题。我在论坛帖子上面得到了解决方案。