I'm currently trying Firebase Remote Config on Android. I gave a parameter a value: 2.2 but when I run an app it prints 2.0 for no reason in Logcat.
here is my code:
initialization:
private FirebaseRemoteConfig mRemoteConfig = FirebaseRemoteConfig.getInstance();
Setting defaults:
mRemoteConfig.setDefaults(hashMap);
Fetching:
mRemoteConfig.setConfigSettings(new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(true).build());
Getting double from remote config:
double code = mRemoteConfig.getDouble("code");
What I have done wrong?
You need to set the time frame to tell Firebase when to fetch the parameter.
Try code below,below example is fetch update for every 60 seconds:
final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
// set in-app defaults
Map<String, Object> remoteConfigDefaults = new HashMap();
remoteConfigDefaults.put("CURRENT_VERSION", "2.0");
//...any other defaults here
firebaseRemoteConfig.setDefaults(remoteConfigDefaults);
firebaseRemoteConfig.fetch(60) // set the value in second to fetch every minutes
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "remote config is fetched.");
}
}
});