TheStudent123 TheStudent123 - 22 days ago 10
Android Question

Android - Firebase - The email address is badly formatted

Aim

Allow users to register their preferred display name, home address, email, and password by utilizing Firebase Authentication (Email and Password)

Java Class

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;

public class RegistrationActivity extends AppCompatActivity {

private TextInputLayout jRegisterName;
private TextInputLayout jRegisterAddress;
private TextInputLayout jRegisterEmail;
private TextInputLayout jRegisterPassword;
private Button jRegisterRegBtn;

//Firebase
private FirebaseAuth mAuth;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);

//Firebase Auth
mAuth = FirebaseAuth.getInstance();

jRegisterName = (TextInputLayout) findViewById(R.id.registerName);
jRegisterAddress = (TextInputLayout) findViewById(R.id.registerAddress);
jRegisterEmail = (TextInputLayout) findViewById(R.id.registerEmail);
jRegisterPassword = (TextInputLayout) findViewById(R.id.registerPassword);
jRegisterRegBtn = (Button) findViewById(R.id.registerRegBtn);

jRegisterRegBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

String userDisplayName = jRegisterName.getEditText().toString();
String userHomeAddress = jRegisterAddress.getEditText().toString();
String userEmail = jRegisterEmail.getEditText().toString().trim();
String userPassword = jRegisterPassword.getEditText().toString().trim();

registerUser(userDisplayName, userHomeAddress, userEmail, userPassword);

}

private void registerUser(String userDisplayName, String userHomeAddress, String userEmail, String userPassword) {
mAuth.createUserWithEmailAndPassword(userEmail, userPassword).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Intent intentMain = new Intent(RegistrationActivity.this, MainActivity.class);
startActivity(intentMain);
finish();
}else if(!task.isSuccessful()){
FirebaseAuthException e = (FirebaseAuthException )task.getException();
Toast.makeText(RegistrationActivity.this, "Failed Registration: "+e.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
}
});
}
});

}
}


Problem

After the user has entered the input such as

Name : JohnSmith

HomeAddress : 18 King Street

Email : johnsmith@gmail.com

Password : 123456789pass

The user fails to register and the message below prompts out

"Failed Registration: The email address is badly formatted"

Answer Source

Check your inputType on the xml file. There is 3 types of inputs on email.

android:inputType="textWebEmailAddress"
android:inputType="textEmailAddress"
android:inputType="textEmailSubject"

More here https://developer.android.com/reference/android/text/InputType.html