我正在开发一款使用Firebase RemoteConfig功能的Android应用。我的代码就像
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);
}
但是当我在FCM控制台中更新相应的Remoteconfig值时,它没有反映在应用程序中。
我也提到了FirebaseRemoteConfig.fetch() does not trigger OnCompleteListener every time。并按照该链接中的建议实现了代码。
所以我实现了代码以实用地清除我的应用缓存。每次在获取Remoteconfig值之前,我都会使用此代码清除我的应用缓存。这对我来说只需要几次迭代。但是现在即使这对我来说也无法获得更新的Remoteconfig值。我的代码是链接
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;
}
}
请指导我100%获取更新的Remoteconfig值的正确方法。先感谢您。任何建议都表示赞赏。
答案 0 :(得分:0)
首先,您必须在调用提取并激活之前设置最小提取间隔
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
int interval = 3600
FirebaseRemoteConfigSettings configSettings =
new FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(interval)
.build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);