Android Play Store provides users to auto-download updates to their apps but it also provides users to stop that auto download. The update to a mobile app does not work like an update to a website i.e while in case of websites the updated website is available to a user without any effort (effort at user’s end), in case of a mobile app the user has to download the updated version of app (if auto download is off).
So are you concerned with how to make your user aware that an update to your app is available on Android Play Store? Well, you can prompt your users by showing them an “Update your App” Screen based on the version of App using Firebase Remote Config. In this post, we are going to implement this functionality. Just follow the steps given below.
We are going to use Firebase Remote Config in this post, so if you are not familiar with Firebase Remote Config or want to learn more about it you can read my previous post, Firebase Remote Config – Android.
Before following the points given below there are some pre-requisites that you need to complete.
- You should have connected your Android App to Firebase i.e. you must have created a project on firebase console and connected it your Android Application. If you have not, then follow the instructions on Firebase Android Setup page and then return to this post.
- You should be developing your Android Project on Android Studio.
Add below-given dependencies to your app-level build.gradle file.
Create In-App Default Values
We will create in-app default parameter values so that your app behaves predictably before it fetches values from the Remote Config service.
- To create default values, we need to define all the parameter names and default parameter values in an XML resource file that is stored your app’s res/xml folder. In our case, we will save app version code which needs to be same as defined in build.gradle file. Copy the content from the below-given xml file and paste it in your file and replace the value of app_vesion_code with your app’s version.
Add Logic to Launcher Activity
- The logic to show Update your App Screen is implemented in your App’s Launcher Activity.
- Launcher Activity is an activity which is launched when your App starts. In most of the cases, this activity is named as MainActivity and works as a Splash Screen.
- In our case, this launcher activity will work as a Splash Screen i.e it should not contain any UI element that involves any user interaction.
- Now copy the whole code given below or copy the necessary blocks of code and paste in your launcher activity.
Create “Update App Screen” Layout File
Now we will create an xml file to define the layout for the Update App Screen. Copy the whole code given below or you can define your own layout.
The xml file above must be showing many errors that is because we have not defined the color and string resources used above in their respective files. Also, the image resource and the button background are not defined yet. While I expect that you can add string and color resources on your own, I am providing the xml file contents for image resource and button background below.
Create JAVA File for “Update App Screen”
Now define the java file for the Update App Screen. Copy the whole code given below if you have defined the same layout given in Step 4 for Update App Screen otherwise copy the necessary blocks of code as per your requirement. I have well commented the code given below so you won’t face any problem.
* Don’t forget to make an entry for the Launcher Activity and the Update your App Activity in AndroidManifest file.
* Update the value for app_version_code in Firebase Remote Config Dashboard every time you publish a new version of your App.
Now I have covered all the necessary steps to make your users aware of the App Update using Firebase Remote Config. But you can always tweak the code given above as per your requirements following the same order of steps.
If you face any problem in the tutorial above, you can always leave a reply or reach me through the chat option given in bottom right corner of the window.