Firebase远程配置,无法获取价值。安卓系统

时间:2019-01-14 21:06:06

标签: android firebase firebase-remote-config

我创建了一些测试项目以学习Firebase远程配置。这是Firebase https://monosnap.com/file/0xgQCL7oo7lyOjBs8CG3kZO0szBXh6中的设置。下面是我的代码:

final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
            FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
                    .setDeveloperModeEnabled(BuildConfig.DEBUG)
                    .build();
            config.setConfigSettings(configSettings);

            String onlineVersion = FirebaseRemoteConfig.getInstance().getString("android_current_version");// empty string

我不知道为什么我不能从Firebase中获得价值

1 个答案:

答案 0 :(得分:0)

也许您需要先获取远程配置:

config.fetch(cacheExpiration)
    .addOnCompleteListener(this, new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                Toast.makeText(MainActivity.this, "Fetch Succeeded",
                        Toast.LENGTH_SHORT).show();

                // After config data is successfully fetched, it must be activated before newly fetched
                // values are returned.
                mFirebaseRemoteConfig.activateFetched();

            } else {
                Toast.makeText(MainActivity.this, "Fetch Failed",
                        Toast.LENGTH_SHORT).show();
            }

            String onlineVersion = FirebaseRemoteConfig.getInstance().getString("android_current_version");// empty string
        }
    })

在“ onComplete”方法中,您可以获得远程配置信息

检查此:Remote Config