Firebase 远程配置 isDeveloperModeEnabled() 已弃用

Firebase Remote Config isDeveloperModeEnabled() is deprecated

我正在尝试使用 Firebase 的远程配置功能获得一个远程配置参数,这样我就可以从 Firebase 获取值并在应用程序中使用它。我已经可以毫无问题地使用它,但在 Firebase 更新后,我收到此警告:

我试图使用 getMinimumFetchIntervalInSeconds() 而不是 isDeveloperModeEnabled() 以避免警告。

这是我的代码:

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();
            }
        }
    });

知道如何解决这个问题吗?

关于setMinimumFetchIntervalInSecondsofficially 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.

虽然您可以 setMinimumFetchIntervalInSeconds 不同于默认值(= 12 小时),但是否达到配额完全取决于您,并可能导致 FirebaseRemoteConfigFetchThrottledException

现在,新的 API 要求您 setMinimumFetchIntervalInSeconds 来更改间隔。是FirebaseRemoteConfigSettings.Builder的方法。所以你必须在setMinimumFetchIntervalInSeconds之后通过builder构建一个FirebaseRemoteConfigSettings对象,然后setConfigSettingsAsync把构建的FirebaseRemoteConfigSettings到你的FirebaseRemoteConfig.

这是我自己实现的一个例子:

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);

------------------------修改---------------- ----------

为了你的目的

checking if package name is the same

您不需要 isDeveloperModeEnabled() 或任何间隔设置。只是 fetch() 没有任何设置(但有默认设置):

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();
            }
        }
    });