5

I'm trying to insert a new user record in to my Firebase database:

 databaseReference .child("users") .child(firebaseUser.getUid()) .setValue(User.fromFirebaseUser(application.firebaseUser)) .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { startActivity(MainActivity.createIntent(SplashActivity.this)); finish(); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { showSnackbar(R.string.error_user_registration_failed); } }) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { Log.d(TAG, "complete"); } }); 

But nothing happens. There is no messages from logcat and none of the listeners get hit.

My permissions are the default (must be authenticated) and I've made sure I am. A call to firebaseUser.getUid() just before the database call returns the current userId as expected.

I've triple checked all my dependencies and made sure my google-services.json file is up to date.

I've tried to enable debugging via firebaseDatabase.setLogLevel() but for some reason Logger.Level doesn't contain the enums (they're obfuscated?)

Am I missing something?

2
  • 2
    Workaround for setLogLevel() problem here: stackoverflow.com/q/44468817/4815718 Commented Jun 17, 2017 at 16:10
  • Sometimes play service in the background freezes and all the firebase system is offline, make sure play services is running ok. Might help. Commented Jun 17, 2017 at 16:27

3 Answers 3

4

Make sure you have "firebase_url": in google-services.json file in project_info": block. Some how in my case the URL option was not created.

Note: In the url option you have to give your firebase database link

Sign up to request clarification or add additional context in comments.

1 Comment

This happens when you create a project and download google-services.json before creating a database. You cured my heartache. I didn't sleep for a night. Thanks.
3

After enabling debugging (thanks Bob Snyder) it gave me an error.

Essentially you need to enable the "Token Service API" in your Google Developer console. I'm not sure why and how this relates to FirebaseDatabase, and I couldn't find any references to it throughout Google's docs, but it worked.

Comments

3

I had the same issue with reading the users data..

I changed the database rules to:

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

And it worked, but make sure you kill the app first after changing and publishing the new rules.

Note: these rules are only for testing and should never be saved for the published app

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.