George Gigauri
George Gigauri

Reputation: 55

Firebase Remote Config - android

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?

Upvotes: 4

Views: 3545

Answers (2)

Lucas P
Lucas P

Reputation: 125

You need to:

  1. call fetch() to fetch the values from Firebase

and

  1. call activateFetched() to activate the values last fetched, whenever appropriate and convenient in your app.

Only after both of those steps are done will you receive the most up-to-date values set in the Firebase Console when you call getDouble("code").

Example usage from Firebase's Quickstart app on Github

Upvotes: 1

ken
ken

Reputation: 2662

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.");

                        }
                    }
                });

Upvotes: 2

Related Questions