Switching between firebase projects at runtime (in Android client)

2,805 views
Skip to first unread message

John O'Reilly

unread,
Sep 4, 2016, 10:48:03 AM9/4/16
to Firebase Google Group
Is it possible, in Android app,  to switch between different firebase projects at runtime?  Right now I include google-services.gson at bulid time which has static info associated with particular project.  What I'd ideally need is some way, at runtime, to set params like "firebase_url" and "project_id" and re-init firebase.

Austin France

unread,
Oct 6, 2016, 10:40:06 AM10/6/16
to Firebase Google Group
I too would like to know how to do this.  Because our app connects to customers server, each customer will need to have their own project setup to handle notifications, so I need to be able to set the entire configuration at runtime, not through google-services.json.

Ian Barber

unread,
Oct 6, 2016, 11:59:51 AM10/6/16
to Firebase Google Group
In most cases, yes. You can create as many instances of FirebaseApp as you need, you just have to enter the config yourself e.g:

FirebaseOptions options = new FirebaseOptions.Builder()

      .setApplicationId("1:530266078999:android:481c4ecf3253701e") // Required for Analytics.

      .setApiKey("AIzaSyBRxOyIj5dJkKgAVPXRLYFkdZwh2Xxq51k") // Required for Auth.

      .setDatabaseUrl("https://project-1765055333176374514.firebaseio.com/") // Required for RTDB.

      .build();

FirebaseApp.initializeApp(this /* Context */, options, "secondary");

// Retrieve my other app.
FirebaseApp app = FirebaseApp.getInstance("secondary");
// Get the database for the other app.
FirebaseDatabase secondaryDatabase = FirebaseDatabase.getInstance(app);\

Note that analytics will only fire for the primary app configured, but otherwise you're pretty flexible.  

Ian

Austin France

unread,
Oct 7, 2016, 4:01:43 AM10/7/16
to Firebase Google Group
There doesn't seem to be an option to set the project ID, is it even needed?

Dne četrtek, 06. oktober 2016 16.59.51 UTC+1 je oseba Ian Barber napisala:

Frank van Puffelen

unread,
Oct 7, 2016, 6:28:36 AM10/7/16
to Firebase Google Group

Austin France

unread,
Oct 7, 2016, 6:28:52 AM10/7/16
to Firebase Google Group
It appears it can't be used for FirebaseMessaging either, as FirebaseMessaging.getInstance() doesn't support a name parameter, so presumably also only works with the default app configuration.
Reply all
Reply to author
Forward
0 new messages