My app fails on authentication new users while registering. The application is connected to Google Firebase and nothing seems to be done wrong with it. Code seems also alright, it displays no errors and I checked everything 10000000 times. Everything needed is already imported. When I try to register new user an error appears which says: "An internal error has occured. [Access Not Configured. Google Identity Toolkit API has not been used in project (here is 12-digit project number) before or it is disabled. Enable it by visiting console.developers.google.com/apis/api/… project number) then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.] I set up authentication yesterday so I don't know what to do...
public class RegisterUserActivity extends AppCompatActivity {
//DECLARE FIELDS
EditText userEmailCreateEditText, userPassWordCreateEditText;
LinearLayout createAccountBtn;
//FIREBASE AUTHENTICATION ID
FirebaseAuth mAuth;
FirebaseAuth.AuthStateListener mAuthListener;
//PROGRESS DIALOG
ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_user);
//ASSIGN ID'S
userEmailCreateEditText = ( EditText ) findViewById(R.id.emailRegisterEditText);
userPassWordCreateEditText = (EditText) findViewById(R.id.passwordRegisterEditText);
createAccountBtn = ( LinearLayout) findViewById(R.id.createAccountSubmitBtn);
//PROGRESS DIALOG INSTANCE
mProgressDialog = new ProgressDialog(this);
//FIREBASE INSTANCE
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
//CHECK USER
FirebaseUser user = firebaseAuth.getCurrentUser();
if( user != null )
{
Intent moveToHome = new Intent(RegisterUserActivity.this, Home.class);
moveToHome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity( moveToHome );
}
}
};
mAuth.addAuthStateListener(mAuthListener);
//CREATE ON CLICK LISTENER
createAccountBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mProgressDialog.setTitle("Create Account");
mProgressDialog.setMessage("Wait while the account is being created..");
mProgressDialog.show();
createUserAccount();
}
});
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
@Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(mAuthListener);
}
//LOGIC FOR CREATING THE USER ACCOUNT
private void createUserAccount() {
String emailUser, passUser;
emailUser = userEmailCreateEditText.getText().toString().trim();
passUser = userPassWordCreateEditText.getText().toString().trim();
if( !TextUtils.isEmpty(emailUser) && !TextUtils.isEmpty(passUser))
{
mAuth.createUserWithEmailAndPassword(emailUser, passUser).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if( task.isSuccessful() )
{
Toast.makeText(RegisterUserActivity.this, "Account created Success", Toast.LENGTH_LONG).show();
mProgressDialog.dismiss();
Intent moveToHome = new Intent(RegisterUserActivity.this, Home.class);
moveToHome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity( moveToHome );
}else
{
Toast.makeText(RegisterUserActivity.this, task.getException().getMessage(), Toast.LENGTH_LONG).show();
mProgressDialog.dismiss();
task.getException().getMessage();
}
}
});
}
}
}