Firebase Remote Config
It helps to change the behavior and appearance of your app without publishing an app update, at no cost, for unlimited daily active users.
What is Firebase Remote Config?
Firebase Remote Config is a cloud service that lets you change the behavior and appearance of your app without requiring users to download an app update. When using Remote Config, you create in-app default values that control the behavior and appearance of your app. Then, you can later use the Firebase console or the Remote Config REST API to override in-app default values for all app users or for segments of your user base. Your app controls when updates are applied, and it can frequently check for updates and apply them with a negligible impact on performance.
Add Firebase to your app
If you haven’t already, add Firebase to your Android project.
Add dependency
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:31.1.0') // Add the dependencies for the Remote Config and Analytics libraries // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-config-ktx' implementation 'com.google.firebase:firebase-analytics-ktx' }
Demo App
I have prepared a Demo App for showing update dialog to the user.
Open Remote Config in Console, Add needed parameters and publish
Add default values
Create remote_config_defaults.xml
file in res>xml
folder
<?xml version="1.0" encoding="utf-8"?> <defaultMap> <entry> <key>latestVersion</key> <value>1</value> </entry> <entry> <key>forceUpdate</key> <value>false</value> </entry> <entry> <key>releaseNotes</key> <value>- test release note</value> </entry> <entry> <key>updateUrl</key> <value>https://play.google.com/store/apps/details?id=com.spinscoins</value> <!--TODO : PLAY STORE URL--> </entry> </defaultMap>
Fetch values from Firebase
val remoteConfig = FirebaseRemoteConfig.getInstance() val configSettings = FirebaseRemoteConfigSettings.Builder() .setMinimumFetchIntervalInSeconds(10) .build() remoteConfig.setConfigSettingsAsync(configSettings) remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults) remoteConfig.fetchAndActivate() val latestVersion = remoteConfig.getInt("latestVersion") val forceUpdate = remoteConfig.getBoolean("forceUpdate") val updateUrl = remoteConfig.getString("updateUrl") val releaseNotes = remoteConfig.getString("releaseNotes") Log.e("TAG", "latestVersion : $latestVersion") Log.e("TAG", "forceUpdate : $forceUpdate") Log.e("TAG", "updateUrl : $updateUrl") Log.e("TAG", "releaseNotes : $releaseNotes")
Check current app version
val currentVersion = BuildConfig.VERSION_CODE
Show dialog if the version is different than the app version
val dialogUpdate = Dialog(this@MainActivity) if (latestVersion > currentVersion) { dialogUpdate.requestWindowFeature(Window.FEATURE_NO_TITLE) dialogUpdate.setContentView(R.layout.dialog_update) dialogUpdate.setCancelable(false) dialogUpdate.tvReleaseNotes.text = releaseNotes dialogUpdate.btnUpdate.setOnClickListener { val intent = Intent(Intent.ACTION_VIEW) intent.data = Uri.parse(updateUrl) startActivity(intent) } if (forceUpdate) { dialogUpdate.btnCancel.visibility = INVISIBLE } else { dialogUpdate.btnCancel.visibility = VISIBLE } dialogUpdate.btnCancel.setOnClickListener { dialogUpdate.dismiss() } dialogUpdate.show() } else { if (dialogUpdate.isShowing) { dialogUpdate.dismiss() } }
Thanks
Your contributions are welcome.