3

According to the Firebase documentation you can initialize multiple apps like this:

FirebaseOptions options = new FirebaseOptions.Builder()
                    .setApplicationId(APPLICATION_ID)
                    .setApiKey(API_KEY)
                    .setProjectId(PROJECT_ID)
                    .setDatabaseUrl(DATABASE_URL)
                    .build();
FirebaseApp.initializeApp(activity, options, "your_app_name");

And to get this explicit instance you can do:

FirebaseApp.getInstance( "your_app_name" );

Then, when you try to access to the FirebaseMessaging instance you just can get the DEFAULT instance:

FirebaseMessaging.getInstance();

What internally executes:

public class FirebaseMessaging {
    public static final String INSTANCE_ID_SCOPE = "FCM";
    private static final Pattern zzolx = Pattern.compile("[a-zA-Z0-9-_.~%]{1,900}");
    private static FirebaseMessaging zzoly;
    private final FirebaseInstanceId zzolz;

    public static synchronized FirebaseMessaging getInstance() {
        if(zzoly == null) {
            zzoly = new FirebaseMessaging(FirebaseInstanceId.getInstance());
        }

        return zzoly;
    }

    private FirebaseMessaging(FirebaseInstanceId var1) {
        this.zzolz = var1;
    }
    ...
}

So you can't do things like:

new FirebaseMessaging( FirebaseApp.getInstance( "your_app_name" ) );

OR

FirebaseMessaging.getInstance( "your_app_name" );

How can you use FirebaseMessaging for an explicit app other the the DEFAULT?

Rafa0809
  • 1,733
  • 21
  • 24
  • did you solve it – Googlian Apr 23 '20 at 14:41
  • I think I didn't... for some other reasons we ended up using PubNub – Rafa0809 Apr 27 '20 at 12:21
  • In case you want to receive messages from a project other than the one defined in your app's `google-services.json` check out this answer that doesn't need a separate instance of `FirebaseMessaging`/`FirebaseApp` https://stackoverflow.com/a/62710006/1916449 – arekolek Jul 03 '20 at 07:15

0 Answers0