0

I am developing an Android app which uses Firebase RemoteConfig feature. And My code is like

protected void onPostResume() {

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

    long cacheExpiration = 0; // 1 hour in seconds 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();
                    } else {
                        //Fetch failed
                    }
                    displayLatestConfigValues();
                }
            });
    super.onPostResume();

}

private void displayLatestConfigValues() {
String coverageAreaString;
      if(mFirebaseRemoteConfig.getBoolean(COVERAGE_AREA_CONFIG_MASTER_KEY))  
{
        coverageAreaString = mFirebaseRemoteConfig.getString(COVERAGE_AREA_CONFIG_KEY);
    } else {
        coverageAreaString = "default area";
      }
        printCoverageArea(coverageAreaString);

}

But when I update the respective Remoteconfig values in FCM console it is not reflecting in the app.

I also referred this FirebaseRemoteConfig.fetch() does not trigger OnCompleteListener every time . And implemented code as suggested in that link.

So I implemented the code to clear my app cache pragmatically. Every time before fetching Remoteconfig values I am clearing my app cache using this code. This worked for me for few iteration. But now even this is not working for me to get updated Remoteconfig value. My code is link

     public static void deleteCache(Context context) {
         try {
            File dir = context.getCacheDir();
            deleteDir(dir);
           } catch (Exception e) {}
      }

  public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
        return dir.delete();
    } else if(dir!= null && dir.isFile()) {
        return dir.delete();
    } else {
        return false;
    }
}  

Please guide me the right way to get updated Remoteconfig value 100% of the time. Thank you in advance. Any suggestion is appreciated.

Community
  • 1
  • 1
Raghuram db
  • 1,471
  • 3
  • 13
  • 19
  • Its a good practice to set the `setDefaults(xml)` to have the defaults value in failure conditions which you are missing! Also make sure you are changing values in Firebase Remote Config console and saving the changes! I was facing the same issue in which I was not saving it properly! – Lalit Poptani Sep 19 '16 at 12:37
  • Hi Lalit Poptani, thanks for your guidance. Actually in my case I am using a default values to show if the latest values from Remoteconfig is not fetched(i.e coverageAreaString = "default area";). And every time I update the values in Remoteconfig I am always doing "PUBLISH CHANGES" action. But still the values are not updating. – Raghuram db Sep 19 '16 at 13:19
  • does this got resolved? I happen to have this issue as well, its not reliable in fetching remote config.. only works sometimes after new build... I'm implementing on iOS.. – Dan Feb 07 '17 at 00:03
  • Yes @John . Its working perfectly fine when I force cleared the cache before requesting for remote config value. – Raghuram db Feb 16 '17 at 06:17

1 Answers1

0

First you have to set minimum Fetch Interval before calling fetch and activate

mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
int interval = 3600 
FirebaseRemoteConfigSettings configSettings = 
       new FirebaseRemoteConfigSettings.Builder()
              .setMinimumFetchIntervalInSeconds(interval)
              .build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
Kratos
  • 329
  • 3
  • 4