0

The default way to add Firebase Messaging to an app is to put a google-services.json configuration in the app root folder. This account is the developer's one and it is fixed, once the app is published it cannot be changed.

Is it possible to allow the user, downloading the app from the store, to configure its own Firebase account and to link the app to its own messaging infrastructure?

KENdi
  • 7,576
  • 2
  • 16
  • 31
Angus
  • 351
  • 3
  • 11
  • 3
    My answer [here](https://stackoverflow.com/a/43623918/4625829) might be useful. – AL. Jun 20 '17 at 09:24
  • 1
    Darn... only noticed that this was tagged with firebase-cloud-messaging after writing my answer. @AL: should this be marked as a duplicate of the question you linked? – Frank van Puffelen Jun 20 '17 at 13:56
  • @FrankvanPuffelen Hi Puf. Possibly. I didn't flag it earlier since I thought the question is still a bit broad, but both posts are very similar when it comes to the desired outcome. – AL. Jun 20 '17 at 14:26

1 Answers1

1

When you include google-services.json in your project, the information in that file is baked into your APK at compile time by the google-services gradle plugin.

But you can also initialize the FirebaseApp instance with values you provide directly in your code. See the example in my answer here: How to connect to more than one firebase database from an android App or this section of the Firebase documentation:

// Manually configure Firebase Options
FirebaseOptions options = new FirebaseOptions.Builder()
    .setApplicationId("1:27992087142:android:ce3b6448250083d1") // Required for Analytics.
    .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") // Required for Auth.
    .setDatabaseUrl("https://myproject.firebaseio.com") // Required for RTDB.
    .build();
FirebaseApp app = FirebaseApp.initializeApp(getApplicationContext(), options);
FirebaseDatabase database = FirebaseDatabase.getInstance(app);

Just ignore the mentions of "multiple projects" in the links - while that is the more common reason for needing this code, it will also work for your need.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807