Firebase Remote Config

Satyam Gondhale
3 min readMar 5, 2021

--

Image source https://firebase.google.com/products/remote-config

Have you ever want to change Behavior & appearance of your app without publishing an app update, at no cost, for unlimited daily active users.🤔🤔
Whoa🤩 🤩 🤩…. Firebase has something for us Firebase Remote Config

But, What it is ?

  1. Cloud Service from Google Firebase
  2. Let user change behavior & appearance without downloading new Update
  3. App can have in-app default values that controls behavior & appearance
  4. As per requirements, using Remote Config Backend Api’s, we can override in-app default values for all app or segment of users
  5. All can happen with a negligible impact on performance

That’s Great, but What can I do with Remote Config 🤔?

  1. Launch new Feature with Percentage Rollout Mechanism 🤩
  2. Define platform & locale-specific promo banners for your app 🤩
  3. Trigger Promotions at a specific time using Remote Config time conditions 🤩
  4. Test new functionality on a limited Testing group 🤩
  5. Use JSON to configure complex entities in your app 🤩
  6. Apply User retention strategies using Firebase Predictions 🤩

Refer to Add Firebase to Android App, before integration of Remote Config for Android. If Firebase already added proceed for further steps.

Steps to Integrate Remote Config in Android

  1. Declare the dependency for the Remote Config Android library in your module (app-level) Gradle file (usually app/build.gradle).
implementation platform('com.google.firebase:firebase-bom:26.6.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-config'

2. Now, get the Firebase Remote Config instance as

FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.getInstance();

3. There can be a requirement to set some properties to RemoteConfig instance in development. It can be done using FirebaseRemoteConfigSettings which wraps the settings for RemoteConfig operations

FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(3600)
.build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);

Note : Configs won’t be fetched from the backend more than once in a 12 hour window. Keep in mind that this setting should be used for development only, not for an app running in production. To set the minimum fetch interval, use FirebaseRemoteConfigSettings.Builder.setMinimumFetchIntervalInSeconds(long)

4. Now, we need to set in-app default value parameters, so that ho should the app behaves if it is not in connection with RemoteConfig backend. To set this values. Add new xml resource directory and xml file, in res folder of Android project and add values as

<?xml version="1.0" encoding="utf-8"?>
<defaultsMap>
<entry>
<key>textview_text</key>
<value>Welcome to Firebase Learning</value>
</entry>
<entry>
<key>textview_font_size</key>
<value>16</value>
</entry>
<entry>
<key>text_color</key>
<value>#42f486</value>
</entry>
</defaultsMap>

5. To set up these defaults values add line

remoteConfig.setDefaultsAsync(R.xml.remote_config_params);

6. To set default values to views

textView.setText(remoteConfig.getString("textview_text"));
textView.setTextSize(remoteConfig.getLong("textview_font_size"));
textView.setTextColor(Color.parseColor(remoteConfig.getString("text_color")));

7. Now, Set parameter values in Remote config Backend and Publish Changes

8. To get those values realtime, RemoteConfig provides set of methods to fetch and set values

remoteConfig.fetchAndActivate().addOnCompleteListener(new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if(task.isSuccessful()){
textView.setText(remoteConfig.getString("textview_text"));
textView.setTextSize(remoteConfig.getLong("textview_font_size"));
String color=remoteConfig.getString("text_color");
textView.setTextColor(Color.parseColor(color));
}
}
});

9. For more info on Remote Config loading strategies

Thanks for your valuable read to article. Last thing, if you feel it helpful, Please SHARE 📤 & do give CLAPS 👏👏.

--

--