Issue
Is it possible to have two different firebase projects instances in one single application? As there can be only one google-services.json.
I have an application where I need to access the two different Realtime Database so how is it possible to have different Firebase instances.
Solution
It is possible. When using just a single database there is a single FirebaseApp object that you don't have to explicitly handle. If you want to connect to another database, you would simply configure that object manually, like this:
FirebaseOptions options = new FirebaseOptions.Builder()
.setApplicationId("YOUR_APP_ID") // Required for Analytics.
.setApiKey("YOUR_API_KEY") // Required for Auth.
.setDatabaseUrl("https://YOUR_FIREBASE_URL.firebaseio.com/") // Required for RTDB.
.build();
FirebaseApp.initializeApp(this /* Context */, options, "secondary");
Then you can access your app by passing in the name you set for the app, then pass that in the request for the database instance:
FirebaseApp app = FirebaseApp.getInstance("secondary");
FirebaseDatabase secondaryDatabase = FirebaseDatabase.getInstance(app);
To be clear, you will still be able to access the other database in the standard way i.e.:
FirebaseDatabase database = FirebaseDatabase.getInstance();
Answered By - sam_c
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.