'setConfigSettings(FirebaseRemoteConfigSettings!): Unit' is deprecated
After reading setConfigSettings and setDeveloperModeEnabled I changed the code to:
firebaseRemoteConfig.setConfigSettingsAsync(
FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(3600L)
.build())
After upgrading to com.google.firebase:firebase-config:19.0.0
the method setDefaults was also deprecated. Replace it with setDefaultsAsync
.
On first run of an application firebaseRemoteConfig
won't fetch data and will return default values. To get actual values and cache them see Android Firebase Remote Config initial fetch does not return value.
Instead of 3600L
you can use time like TimeUnit.HOURS.toSeconds(12)
(as proposed by @ConcernedHobbit).
To supplement CoolMind's answer, I found you have (at least) two options when it comes to setting the minimum fetch interval (setMinimumFetchIntervalInSeconds). You can either do as CoolMind said when you build your remoteConfig object (in Kotlin):
firebaseRemoteConfig.setConfigSettingsAsync(
FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(TimeUnit.HOURS.toSeconds(12))
.build())
or you can set the value within your fetch command as a supplied parameter. This example is also in Kotlin, and I've expanded my code to try and make it very clear what's going on:
remoteConfig.setConfigSettingsAsync(FirebaseRemoteConfigSettings.Builder().build())
// Fetch the remote config values from the server at a certain rate. If we are in debug
// mode, fetch every time we create the app. Otherwise, fetch a new value ever X hours.
var minimumFetchInvervalInSeconds = 0
if (BuildConfig.DEBUG) {
minimumFetchInvervalInSeconds = 0
} else {
minimumFetchIntervalInSeconds = TimeUnit.HOURS.toSeconds(12)
}
val fetch: Task<Void> = remoteConfig.fetch()
fetch.addOnSuccessListener {
remoteConfig.activate()
// Update parameter method(s) would be here
}