Firebase Remote Config: Can't read any values,

2019-02-05 12:32发布

I'm trying to have a remote config parameter using the new Remote Config feature of Firebase, and I'm having an issue.

Here's my Remote Config console: remote config console

I'm doing a fetch and update in my Application's onCreate():

final FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.getInstance();
remoteConfig.fetch().addOnCompleteListener(new OnCompleteListener<Void>() {
    @Override
    public void onComplete(@NonNull Task<Void> task) {
        if (task.isSuccessful()) {
            remoteConfig.activateFetched();
        }
    }
});

And here's how I'm reading it:

FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.getInstance();
String value = remoteConfig.getString("active_subscriptions");

Value is returning null.

If I call remoteConfig.getInfo().getLastFetchStatus(), it returns LAST_FETCH_STATUS_SUCCESS, so it seems the fetch is going through successfully.

Any idea why my value is blank?

8条回答
走好不送
2楼-- · 2019-02-05 13:04

I also encountered this problem. Turns out I hadn't seen the 'Publish' button in the the Firebase console. :facepalm:

查看更多
forever°为你锁心
3楼-- · 2019-02-05 13:05

Found the problem.

After adding some logging, I found that the fetch job's onComplete() was never being called. I moved the fetch from my Application's onCreate to a fragment's, and now it works properly!

(Ian Barber, this might be something to look into or clarify, as the logs indicated that Firebase was initialized without an issue when it was in the Application, and the fetches were silent failures.)

查看更多
登录 后发表回答