Android Firebase Remote Config Force Update

Guilherme Butzen Kunz
3 min readAug 10, 2022

--

Mobile apps are not like web apps. People download their apps from the app stores and update them if there is a new version. They can use the old version of your app at any time. Let’s say the old version of your app is no longer functional. Then you fix that and upload your new version to the store, but what if the user turned off auto-update what happens? So they think your app is bad, complain about the app, give it only one star and a bad review. Which ruins the app’s reputation.

There are several ways to implement a forced update mechanism, in this tutorial we will use Firebase Remote Config.

First, connect Firebase to your project. There are several tutorials that teach you how to do this. Follow the official Firebase documentation.

After connecting your app with Firebase, go to the Firebase platform, in the side menu, in the engagement session, open Remote Config and add the following parameters as in the following image:

So what does each parameter mean:

  • android_force_update_current_version is the current version of the app that you published in the store;
  • android_force_update_required is where you will set a boolean to define the force update activity, whether you want to activate the service or keep it inactive;
  • android_force_update_store_url is where you will store the app’s store address;

The reason we use Firebase Remote Config is that we can enable and disable the service without modifying your app’s code or generating a new version of the app.

So let’s code

First add the Remote Config dependency

implementation 'com.google.firebase:firebase-config-ktx'

Then you can create a class just to check if the forced update is needed or not, but since here is code just to demonstrate the functionality I will do everything in MainActivity. So let’s initialize Firebase Remote Config with the following code:

Then we can also create our constants that will be used in MainActivity:

Now then let’s create the check function that will check if the forced update is necessary or not:

This function will be called in OnResume()

So what we do in this code, first we take the current version of the app and save it in the appVersion variable. The method used to get the current version of the app is as follows:

Next we see that if the currentVersion variable that we fed the android_force_update_current_version is greater than the appVersion that we fed earlier, we display a dialog.

What we have is a dialog that contains the UPDATE button that will launch the Play Store with the following code:

Remember that whenever you upload a new version to the store, you have to change the version that is saved in the variables in Firebase’s Remote Config.

That’s it

Complete Class Code:

MainActivity

ForceUpdateUtils

Dialog

Example app on GitHub: FirebaseRemoteConfigForceUpdate

That’s all, put it to good use!

References:

https://firebase.google.com/docs/android/setup#:~:text=Open%20the%20Firebase%20Assistant:%20Tools,your%20Android%20project%20with%20Firebase.

https://firebasetutorials.com/firebase-remote-config-force-update/

--

--

Guilherme Butzen Kunz

Android Developer | Kotlin Developer | Computer Science Student