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.