Android Studio Firebase Not Entering Data

Asked

Viewed 121 times

0

Does anyone know how to input data into the Firebase Realtime database? My application does not give errors but does not insert anything in Firebase.

Note: Database and application are connected and synchronized.

in Firebase, my database is search-inc. I want to create a data tree, like:

buscacerto-inc
     |___users
           |___id
           |   |____Nome
           |   |____cpf
           |   |____email
           |
           |___id
               |____Nome
               |____cpf
               |____email

My code is this:

try{
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference refer = database.getReference("buscacerto-inc/users");
    Usuario usuario = new Usuario(email, senha); //Minha classe Usuario
    refer.push().setValue(usuario.pegaEmail(), usuario.pegaSenha());
    Toast.makeText(actCadastro.this, "Usuário cadastrado com sucesso!!!", Toast.LENGTH_SHORT).show();
}catch (Exception ex){
    Toast.makeText(actCadastro.this, "Erro: " + ex.getMessage(), Toast.LENGTH_SHORT).show();
}

As I said, it does not generate errors and seems to access Firebase without problems. I am using public Getters (user.pegaEmail) to not leave the Class fields exposed. I pushed() because I want to create a unique id for each one.

  • You don’t need to put "solved" in the title. I know it’s common practice in many forums, but here it’s different. You have already marked a reply below with and this is enough to indicate that it has been solved.

2 answers

0


Diogo, Thank you so much for your reply, but there must have been something wrong with my code/application because I created another project from scratch, connected to the same application database that was giving problems and worked.

So I went to the Firebase settings of my app that was giving problems and, in the tab Cloud Messaging, erased all the Server keys.

Apagando Chave do servidor

After that, Firebase itself created a new key and the app was able to insert new users.

Thank you Diogo.

0

I use the Cloud Firestore, never used the Realtime Database. In my case:

FirebaseFirestore db = FirebaseFirestore.getInstance();
Usuario usuario = new Usuario("Login","Password");
db.collection("usuarios")
                .add(usuario)
                .addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
                    @Override
                    public void onSuccess(DocumentReference documentReference) {
                        Toast.makeText(actCadastro.this, "Usuário cadastrado com sucesso!!!", Toast.LENGTH_SHORT).show();
                    }
                })
                .addOnFailureListener(e -> {
                    Toast.makeText(actCadastro.this, "Falha ao cadastrar Usuario", Toast.LENGTH_SHORT).show();
                });

In the Realtime database it shouldn’t be much different. I hope I helped!

Browser other questions tagged

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