Is there a way to override Firebase Remote Config's Region/Country

2.8k views Asked by At

I override the Locale of my Android App at startup and allow to change the region at runtime. I'm settings the Locale like this:

    Resources res = context.getResources();
    Configuration configuration = res.getConfiguration();
    DisplayMetrics metrics = res.getDisplayMetrics();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        configuration.setLocale(locale);
    }else{
        configuration.locale = locale;
    }
    Locale.setDefault(locale);
    res.updateConfiguration(configuration, metrics);

Now i want to use Firebase-Remote-Config with a Region/Country Condition. e.g.

test_property -> fr_FR = Bonjour 
              -> de_DE = Hallo
              -> default = Hi

If i now have my Device set to de_DE and my app set to fr_FR i will get the test_property from the de_DE region (Hallo). What i want to get is the test_property for the region fr_FR set by the app.

I tried to FirebaseApp.initializeApp(...) after changing the region in the app, but Firebase seems to get the region from somewhere else.

Does someone know a way to set/override the region programmatically so firebase will use that region for the region condition?

I don't want to use Firebase Analytics User Properties, as they get updated way too late.

1

There are 1 answers

1
Mussa On

In your Firebase Console:

a) Set a user property for locale. Go to Analytics menu and select USER PROPERTIES tab.

  1. Provide user property name. Like user_locale.
  2. Add description, save, and publish changes.

b) Set a condition for remote configs. Go to Remote Config menu and select CONDITIONS tab.

  1. Select User property - user_locale.
  2. Select FOR TEXT - exactly matches.
  3. Put locale you need. Like de for German.
  4. Put name like translation_de for condition and select a color.
  5. Save and publish changes.

c) For every remote config parameter add value for condition.

  1. From drop down menu select appropriate condition like translation_de.
  2. Update and publish changes.

On locale change in your code set User Property

FirebaseAnalytics.getInstance(getContext())
    .setUserProperty("user_locale", "de");
FirebaseRemoteConfig.getInstance()
    .fetch(1)
    .addOnCompleteListener(activity, new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                FirebaseRemoteConfig.getInstance().activateFetched();
            }
        }
    });