2

I'm trying to connect to another database on an Android App, and can't seem to see if I've successfully init the secondary database.

How I'm instantiating the second one.

public void initFirebase() {
    //init the default db;
    FirebaseApp.initializeApp(this);

    //init the second db;
    FirebaseOptions.Builder builder = new FirebaseOptions.Builder();
    builder.setApplicationId("id");
    builder.setApiKey("key");
    builder.setDatabaseUrl("https://second-db.firebaseio.com");

    try {
        FirebaseApp.initializeApp(this, builder.build(), "second-db");
    } catch (IllegalStateException e) {
        e.printStackTrace();
    }
}

Then I try to read something here.

public static DatabaseReference getSecondDbRef(String child) {
    FirebaseApp app = FirebaseApp.getInstance("second-db");
    return FirebaseDatabase.getInstance(app).getReference(child);
}

Then this fails with some: Listen at /child/child/child/teams failed: DatabaseError: Permission denied, though I've allowed access at this location and can confirm with the rules simulator that this node can be read.

Is there a way to have this log: Listen to second-db/child/child/child/teams failed ..., notice the prefix second-db.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Relm
  • 7,923
  • 18
  • 66
  • 113
  • 1
    i think you have to go this url https://stackoverflow.com/questions/37874920/can-multiple-android-application-access-same-firebase-database – Rohit Aug 23 '18 at 10:56
  • @Rohit that question is not related to what I'm asking. I want to access two different databases from the same Android app, not the same database from two different Android apps. – Relm Aug 23 '18 at 16:07
  • Just add another Firebase Instance in the Activity. Then call the Value Event Listener for the child that related to the 2nd DB instance. Such as in here, https://stackoverflow.com/questions/50160542/using-2-or-more-firebase-realtime-db-inside-a-single-activity – Infinite Loops Aug 23 '18 at 18:59

0 Answers0