Error sending data to Firebase

Asked

Viewed 316 times

1

Good afternoon, I am developing an application and I am having problems sending the data to Firebase...

I created a Registration screen where you have the email field, password and name. I imported the Gradle Compile equal to the firebase documentation shows and made a condition if an error shows a Toast.

My problem is I don’t know what’s going on because I put a log in. i to see if it is recovering the gettext from my fields and is being recovered. I do not know why it is giving error. When checking in Firebase my Authentication database is empty.

Cadastrotela.Activity:

package com.nathan.whatsapp.whatsapp.activity;

import android.support.annotation.NonNull;
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.EditText;
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.database.DatabaseReference;
import com.nathan.whatsapp.whatsapp.Model.SettingFireBase;
import com.nathan.whatsapp.whatsapp.Model.Usuario;
import com.nathan.whatsapp.whatsapp.R;

public class CadastroTela extends AppCompatActivity {

    private EditText nome, email, senha;
    private Button cadastrar;
    private Usuario usuario;
    private FirebaseAuth autenti;


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

        nome = (EditText) findViewById(R.id.edtNomeCadastro);
        email = (EditText) findViewById(R.id.edtEmailCadastro);
        senha = (EditText) findViewById(R.id.edtSenhaCadastro);
        cadastrar = (Button) findViewById(R.id.btnCadastrar);


        cadastrar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                usuario = new Usuario();
                usuario.setNome(nome.getText().toString());
                usuario.setEmail(email.getText().toString());
                usuario.setSenha(senha.getText().toString());
                cadastrarUsuario();
            }
        });
    }

    public void cadastrarUsuario(){
        autenti = SettingFireBase.getFirebaseAuth();

        autenti.createUserWithEmailAndPassword(
                usuario.getEmail(),
                usuario.getSenha()
        ).addOnCompleteListener(CadastroTela.this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if(task.isSuccessful()){
                    Toast.makeText(getApplicationContext(), "Sucesso ao cadastrar o usuario", Toast.LENGTH_SHORT).show();
                    Log.i("LOG", usuario.getEmail());
                    Log.i("LOG", usuario.getSenha());
                }else{
                    Toast.makeText(getApplicationContext(), "Erro ao cadastrar o usuario", Toast.LENGTH_SHORT).show();
                    Log.i("LOGS", usuario.getEmail());
                    Log.i("LOGS", usuario.getSenha());
                }
            }
        });
    }
}

Settingfirebase:

package com.nathan.whatsapp.whatsapp.Model;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

/**
 * Created by nathan on 10/07/2017.
 */

public final class SettingFireBase {

    private static DatabaseReference databaseReference;
    private static FirebaseAuth firebaseAuth;

    //quando precisar recuperar todas as informações do firebase
    public static DatabaseReference getFirebase(){

        if(databaseReference == null){
            databaseReference = FirebaseDatabase.getInstance().getReference();
        }

        return databaseReference;
    }

    public static FirebaseAuth getFirebaseAuth(){
        if(firebaseAuth == null){
            firebaseAuth = FirebaseAuth.getInstance();
        }

        return firebaseAuth;
    }
}

Usuario (String):

package com.nathan.whatsapp.whatsapp.Model;

public class Usuario {
    private String id;
    private String nome;
    private String email;
    private String senha;

    public Usuario() {
//        this.id = id;
//        this.nome = nome;
//        this.email = email;
//        this.senha = senha;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }
}

Detail:

  • my login method in firebase is enabled as email
  • My database rules ( true, true)

Could someone please help me? Thank you guys

No answers

Browser other questions tagged

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