Good afternoon, I'm developing an application and I'm having trouble sending the data to Firebase ...
I created a Cadastre screen where you have the email field, password and name. I imported the gradile compile equal to the firebase documentation shows and made a condition if I have a toast display error.
My problem is that I do not know what's happening because I put a Log.i to see if it's retrieving getText from my fields and it's being retrieved. I do not know why this is making a mistake. When checking in Firebase my authentication bank 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;
}
}
User (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 anyone help me please? Thank you guys