0

I'm working with Firebase on Android Studio recently , i was following the guide to insert data to Firebase Realtime Data but it seems to be not working eventhough i tried many ways to find out the error. So please help me . My app just really simple , just register , sign in , signout . I got my Register and Sign in / Signout working perfectly with Firebase. Then i move on : I added example code under

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

in the MainActivity so it will send this every time i open the app ( just to test )

 FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("messages");

    myRef.setValue("Hello, World!");

It never work, enter image description here

I also tried reimport my gooogle-services.json file after set-up the Realtime Database but it not work too. Please tell me where did i make mistake and why i can login/register normally but i can't send the data to database . Many thanks.

phvtquang
  • 35
  • 5
  • Everything looks fine to me. However, did you check your Security & Rules? – minchaej Jun 22 '21 at 19:44
  • 1
    Is your database hosted in the US (default) or in one of the other regions? If one of the other, you need to specify the database URL in your call to `FirebaseDatabase.getInstance("database URL here")`. See https://stackoverflow.com/questions/67795058/getinstance-doesnt-work-with-other-location-than-us-central1-in-realtime-data – Frank van Puffelen Jun 22 '21 at 19:45
  • 1
    wow , it's really solve the problem that i've spent all day to find out , thank you very much @FrankvanPuffelen .It's work now. – phvtquang Jun 22 '21 at 19:49
  • 1
    Just spotted the region in your screenshot, so the fix is indeed to specify the URL in code. – Frank van Puffelen Jun 22 '21 at 19:53

0 Answers0