简体   繁体   English

Firebase 远程配置 - android

[英]Firebase Remote Config - android

I'm currently trying Firebase Remote Config on Android.我目前正在 Android 上尝试 Firebase 远程配置。 I gave a parameter a value: 2.2 but when I run an app it prints 2.0 for no reason in Logcat.我给了一个参数一个值:2.2 但是当我运行一个应用程序时,它在 Logcat 中无缘无故地打印 2.0。

here is my code:这是我的代码:

initialization:初始化:

private FirebaseRemoteConfig mRemoteConfig = FirebaseRemoteConfig.getInstance();

Setting defaults:设置默认值:

mRemoteConfig.setDefaults(hashMap);

Fetching:获取:

mRemoteConfig.setConfigSettings(new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(true).build());

Getting double from remote config:从远程配置获得双倍:

double code = mRemoteConfig.getDouble("code");

What I have done wrong?我做错了什么?

You need to:你需要:

  1. call fetch() to fetch the values from Firebase调用fetch()从 Firebase 获取值

and

  1. call activateFetched() to activate the values last fetched, whenever appropriate and convenient in your app.调用activateFetched()以激活上次提取的值,只要在您的应用程序中合适且方便。

Only after both of those steps are done will you receive the most up-to-date values set in the Firebase Console when you call getDouble("code") .只有在完成这两个步骤后,您才会在调用getDouble("code")时收到 Firebase 控制台中设置的最新值。

Example usage from Firebase's Quickstart app on Github Github 上 Firebase 快速入门应用的使用示例

You need to set the time frame to tell Firebase when to fetch the parameter.您需要设置时间范围以告知 Firebase 何时获取参数。

Try code below,below example is fetch update for every 60 seconds:试试下面的代码,下面的例子是每 60 秒获取一次更新:

 final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance();

 // set in-app defaults
 Map<String, Object> remoteConfigDefaults = new HashMap();
 remoteConfigDefaults.put("CURRENT_VERSION", "2.0");
  //...any other defaults here

 firebaseRemoteConfig.setDefaults(remoteConfigDefaults);
 firebaseRemoteConfig.fetch(60) // set the value in second to fetch every minutes
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()) {
                            Log.d(TAG, "remote config is fetched.");

                        }
                    }
                });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM