After upgrading Firebase libraries to
implementation "com.google.firebase:firebase-messaging:18.0.0"
implementation 'com.google.firebase:firebase-config:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
and syncing Gradle, I got warning:
'setConfigSettings(FirebaseRemoteConfigSettings!): Unit' is deprecated. Deprecated in Java
'setDeveloperModeEnabled(Boolean): FirebaseRemoteConfigSettings.Builder!' is deprecated. Deprecated in Java
in these lines:
//Setting Developer Mode enabled to fast retrieve the values
firebaseRemoteConfig.setConfigSettings(
FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(BuildConfig.DEBUG)
.build())
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With