2016-11-10 73 views
1

我在尝试注册模拟器和我的设备时不断收到此错误。身份验证failed.com.google.firebase.FirebaseException:发生内部错误。 [OPERATION_NOT_ALLOWED]

身份验证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

请检查是否在控制台中启用身份验证方法Firebase与否。 如果您未启用Google身份验证,则会出现相同的例外情况,只是没有[OPERATION_NOT_ALLOWED]。

欲了解更多信息,您可以在论坛上发帖https://groups.google.com/forum/#!topic/firebase-talk/JTaIlD-tNxw

检查解决方案请检查Firebase Auth文档的详细信息。

我有同样的问题。我在上面的论坛帖子中找到了解决方案。

+0

我确实启用了身份验证方法,但它仍然给我[OPERATION_NOT_ALLOWED] – zeeman235

+0

检查此链接http://stackoverflow.com/questions/37465624/firebase-password-reset-keep-getting-error-an-internal-error -has-occured-er –

+0

从头开始重新编译项目似乎已经解决了这个问题,谢谢。 – zeeman235