Reputation: 58
I'm trying to have a remote config parameter using the Remote Config feature of Firebase so I can get values from Firebase and use it in app. I already use it with no problem but after a Firebase update, I get this warning:
I tried to use getMinimumFetchIntervalInSeconds()
instead of isDeveloperModeEnabled()
in order to avoid the warning.
Here is my code:
final FirebaseRemoteConfig mFirebaseRemopteconfig = FirebaseRemoteConfig.getInstance();
long cachExpiration = 0;
if (mFirebaseRemopteconfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) {
cachExpiration = 0;
}
mFirebaseRemopteconfig.fetch(cachExpiration)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
final String funct = mFirebaseRemopteconfig.getString("functionn");
if (getPackageName().compareTo(funct) != 0) {
finish();
}
mFirebaseRemopteconfig.activateFetched();
}
}
});
Any idea how to solve this problem?
Upvotes: 2
Views: 2846
Reputation: 12478
About setMinimumFetchIntervalInSeconds
, it is officially said:
Keep in mind that this setting should be used for development only, not for an app running in production. If you're just testing your app with a small 10-person development team, you are unlikely to hit the hourly service-side quota limits. But if you pushed your app out to thousands of test users with a very low minimum fetch interval, your app would probably hit this quota.
Although you can setMinimumFetchIntervalInSeconds
other than the default value (= 12 hours), it's all up to you about whether it would hit the quota or not, and may lead to FirebaseRemoteConfigFetchThrottledException
.
Now, the new API requires you to setMinimumFetchIntervalInSeconds
for altering the interval. It is a method of FirebaseRemoteConfigSettings.Builder
. So you must build a FirebaseRemoteConfigSettings
object through the builder after setMinimumFetchIntervalInSeconds
, and then setConfigSettingsAsync
the built FirebaseRemoteConfigSettings
to your FirebaseRemoteConfig
.
Here is an example of my own implementation:
if (BuildConfig.DEBUG) {
cacheExpiration = 0;
} else {
cacheExpiration = 43200L; // 12 hours same as the default value
}
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings
.Builder()
.setMinimumFetchIntervalInSeconds(cacheExpiration)
.build();
config = FirebaseRemoteConfig.getInstance();
config.setConfigSettingsAsync(configSettings);
config.fetch(cacheExpiration).addOnCompleteListener(activity, onCompleteListener);
--------------------------- revised ---------------------------
For your porpose
checking if package name is the same
you don't need isDeveloperModeEnabled()
or any interval settings. Just fetch()
without any settings (but with default settings):
mFirebaseRemopteconfig = FirebaseRemoteConfig.getInstance();
mFirebaseRemopteconfig.fetch()
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
final String funct = mFirebaseRemopteconfig.getString("functionn");
if (getPackageName().compareTo(funct) != 0) {
finish();
}
mFirebaseRemopteconfig.activateFetched();
}
}
});
Upvotes: 4