0

I try to fetch specific values from remote config in Firebase, but it always gives me the value that I defined in client side the first time.

Here is my code:

 public static final int DEFAULT_MSG_LENGTH_LIMIT = 1000;
private static final String FRIENDLY_MSG_LENGTH_KEY ="friendly_msg_length";

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(BuildConfig.DEBUG).build();
    mFirebaseRemoteConfig.setConfigSettings(configSettings);

    Map<String, Object> defaultConfigMap = new HashMap<>();
    defaultConfigMap.put(FRIENDLY_MSG_LENGTH_KEY, DEFAULT_MSG_LENGTH_LIMIT);
    mFirebaseRemoteConfig.setDefaults(defaultConfigMap);
    fetchCnfig();
}

private void fetchCnfig() {
    long cacheExpiration = 3600;
    if(mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()){
        cacheExpiration = 0;
    }
    mFirebaseRemoteConfig.fetch(cacheExpiration)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if(task.isSuccessful()){
                        mFirebaseRemoteConfig.activateFetched();
                        applyRetrievedLengthLimit();
                    }else{
                        Log.w(TAG, "error fetching config" + task.getException().getMessage());
                        applyRetrievedLengthLimit();
                    }
                }
            });
}

private void applyRetrievedLengthLimit() {
    long friendly_msg_length = mFirebaseRemoteConfig.getLong(FRIENDLY_MSG_LENGTH_KEY);
    mMessageEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(((int) friendly_msg_length))});
}

Any idea what could be wrong would be evaluated

AL.
  • 36,815
  • 10
  • 142
  • 281

2 Answers2

0

After updating value you need to Publish changes from firebase console

enter image description here

After the changes are published, it will be available to end users and you can fetch that value in application.

Ravi
  • 34,851
  • 21
  • 122
  • 183
  • This was done but still doesn't change the values received from the firebase –  Jan 21 '17 at 19:27
0

My bug was that I put FRIENDLY_MSG_LENGTH_KEY value at firebase project and I had to put the value of this property (friendly_msg_length in my case)

Hope it can help for everybody :)