Connection app with firebase

Asked

Viewed 233 times

0

Good afternoon, I have the following error in my logcat, when trying to register an email and password in firebase Authentication, where it jumps to my "Else" of "Alert" and soon after the error in "logcat"

error: "E/Zygote: isWhitelistProcess - Process is Whitelisted"

Test performed on Samsung device with android Oreo 8.0, I saw something related to permissions on that version not sure if that would be the reason for the error.

follows the code of my connection class, registration and Gradle App.

import android.support.annotation.NonNull;
import com.firebase.client.Firebase;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class Conexao {

private static FirebaseAuth firebaseAuth;
private static  FirebaseAuth.AuthStateListener authStateListener;
private static FirebaseUser firebaseUser;

private  Conexao(){
}

public static FirebaseAuth getFirebaseAuth(){
    if(firebaseAuth==null){
        inicializarFirebaseAuth();
    }
    return firebaseAuth;
}

private static void inicializarFirebaseAuth(){
    firebaseAuth = FirebaseAuth.getInstance();
    authStateListener =  new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if(user!= null){
                firebaseUser = user;
            }

        }
    };
    firebaseAuth.addAuthStateListener((authStateListener));
}

public static FirebaseUser getFirebaseUser(){
return firebaseUser;
}

public static void logOut(){
    firebaseAuth.signOut();

}
}

My user registration activity:

public class RegistroPessoaActivity extends AppCompatActivity {


private Button btnCadastrar;
private EditText dtNascimento;
private EditText nome;
private EditText email;
private EditText senha;
private EditText confiSenha;
private FirebaseAuth auth;

@Override
protected void onStart() {
    super.onStart();
    auth = Conexao.getFirebaseAuth();
}

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

    dtNascimento = (EditText) findViewById(R.id.textData);
    nome = (EditText) findViewById(R.id.edit_Nome);
    email = (EditText) findViewById(R.id.edit_Email);
    senha = (EditText) findViewById(R.id.edit_CadSenha);
    confiSenha = (EditText) findViewById(R.id.edit_ConfiSenha);
    btnCadastrar = (Button) findViewById(R.id.btn_cadastrar);

   /* String [] countries={"  ","Fisíca", "Jurídica"};
    ArrayAdapter<String> adapter =  new ArrayAdapter<String> 
    (this,android.R.layout.simple_spinner_dropdown_item,countries);
    editSpinner.setAdapter(adapter);*/

    SimpleMaskFormatter Maskdata = new SimpleMaskFormatter("NN/NN/NNNN");
    MaskTextWatcher DataText = new MaskTextWatcher(dtNascimento, Maskdata);
    dtNascimento.addTextChangedListener(DataText);

    btnCadastrar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String Email = email.getText().toString().trim();
            String Senha = senha.getText().toString().trim();
            String Nome = nome.getText().toString().trim();
            String ConfiSenha = confiSenha.getText().toString().trim();
            String DtNascimento = dtNascimento.getText().toString().trim();
            criarUser(Email, Senha);

        }
    });

}
private void alert(String msg){

Toast.makeText(RegistroPessoaActivity.this,msg,Toast.LENGTH_LONG).show();

}

private void criarUser(String email, String senha){

    auth.createUserWithEmailAndPassword(email,senha).addOnCompleteListener(RegistroPessoaActivity.this,
            new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if(task.isSuccessful()){
                alert("Usuario cadastrado com sucesso");
                Intent intent = new Intent(RegistroPessoaActivity.this, PerfilActivity.class);
                startActivity(intent);
                finish();

            }else{
                alert("Erro ao cadastrar usuario");
            }
        }
    });

}

}

Now the Gradle from my app:

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "br.com.softtech.eufaco"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
   "android.support.test.runner.AndroidJUnitRunner"
 }
   buildTypes {
      release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
 'proguard-rules.pro'
    }
 }
 packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE-FIREBASEtxt'
    exclude 'META-INF/NOTICE'
  }
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.firebase:firebase-client-android:2.5.2'
implementation 'com.google.firebase:firebase-database:17.0.0'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso- 
core:3.0.2'

implementation 'com.koushikdutta.ion:ion:2.2.1'

}
dependencies {
  implementation("com.github.bumptech.glide:glide:4.7.1") {
    exclude group: "com.android.support"
}
implementation "com.android.support:support-fragment:28.0.0"
implementation 'com.github.rtoshiro.mflibrary:mflibrary:1.0.0'
implementation 'com.android.support.constraint:constraint-layout:'
}
apply plugin: 'com.google.gms.google-services'

Who can please I am with a certain urgency I thank any and all help!

1 answer

1

First boot Firebase on onCreate:

auth = FirebaseAuth.getInstance();

Try to capture the exceptions released at the time of registering a new user:

private void criarUser(String email, String senha){

auth.createUserWithEmailAndPassword(email,senha).addOnCompleteListener(RegistroPessoaActivity.this,
        new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        if(task.isSuccessful()){
            alert("Usuario cadastrado com sucesso");
            Intent intent = new Intent(RegistroPessoaActivity.this, PerfilActivity.class);
            startActivity(intent);
            finish();

        }else {
            String excecao;

            try{
                throw Objects.requireNonNull(task.getException());
            }
            catch (FirebaseNetworkException ex){
                excecao = "Verifique sua conexão com a internet.";
            }
            catch (FirebaseAuthWeakPasswordException ex){
                excecao = "Senha fraca. Utilize ao menos seis caracteres contendo letras e números.";
            }
            catch (FirebaseAuthUserCollisionException ex){
                excecao = "E-mail já cadastrado.";
            }
            catch (FirebaseAuthInvalidCredentialsException ex){
                excecao = "O e-mail fornecido é inválido.";
            }
            catch (Exception ex){
                excecao = "Erro ao tentar cadastrar.";
                ex.printStackTrace();
            }

            alert("excecao");
    }
});

}

You can also debug and see what the method Conexao.getFirebaseAuth() is returning. We also assume that you have asked for permission to use the internet in your manifest and have the method of authentication by email and password enabled in the Firebase Console.

  • Yes, the manifest is already with internet permission set yes and configured method.

  • Got some head start?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.