0

Firebase realtime database is not updating. What can i change in this code? I have add all the dependencies in the code. I am getting the data from user class.

package com.example.chatapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.chatapp.Model.Users;
import com.example.chatapp.databinding.ActivitySighnupBinding;
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.FirebaseUser;
import com.google.firebase.database.FirebaseDatabase;

public class sighnup extends AppCompatActivity {
    private FirebaseAuth mAuth;
  ActivitySighnupBinding binding;
  FirebaseDatabase database;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding=ActivitySighnupBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        mAuth=FirebaseAuth.getInstance();
        database=FirebaseDatabase.getInstance();

        binding.sighnup.setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View v) {mAuth.createUserWithEmailAndPassword(binding.email.getText().toString(),binding.passoward.
                            getText().toString()).
                        addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override public void onComplete(@NonNull Task<AuthResult> task) {
                        if(task.isSuccessful()){
                            Users users=new Users(binding.username.getText().toString(),binding.email.
                                    getText().toString(),binding.passoward.getText().toString());
                            String id=task.getResult().getUser().getUid();
                            database.getReference().child("Users").child(id).setValue(users);

                            Toast.makeText(sighnup.this,"success",Toast.LENGTH_SHORT).show();
                        }else{
                            Toast.makeText(sighnup.this,"error ",Toast.LENGTH_SHORT).show();

                        }





                    }
                });

            }
        });

Security rules:

{
    "rules": {
      ".read": true,
      ".write": true
     }
}

what can i change on this code?I have tried many ways but in firebase realtime data base it is not uploading.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    Did you download the `google-services.json` file **after** you created the database in the Firebase console? If not, try specifying the URL for your database directly in your code: `database=FirebaseDatabase.getInstance("database URL here");` – Frank van Puffelen Jun 18 '22 at 18:56
  • Most likely this [answer](https://stackoverflow.com/questions/67795058/save-android-user-credentials-to-firebase-database-kotlin/) will help. – Alex Mamo Jun 19 '22 at 08:23

0 Answers0