Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Remote Config fetch doesn't update values from the Cloud

I'm trying to set up Firebase Remote Config for my project. I added Firebase via the Assistant. I added values to the server values on Google Cloud Console:

1

I've created default values xml in res/xml

<defaultsMap>

<!-- Strings-->
<entry >
    <key>textView_send_text</key>
    <value >your phrase goes here.</value>
</entry>

</defaultsMap>

Thats my MainActivity:

final private FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();

protected void onCreate(Bundle savedInstanceState) {
    //..code..

    //fetch from Firebase
    fetchAll();
}

private void fetchAll(){
     final FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();

    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(BuildConfig.DEBUG)
            .build();
    mFirebaseRemoteConfig.setConfigSettings(configSettings);

    mFirebaseRemoteConfig.setDefaults(R.xml.defaults);

    mFirebaseRemoteConfig.fetch()
            .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();

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

                    displayWelcomeMessage();

                }
            });





}

private void displayWelcomeMessage(){
    String welcomeMessage = mFirebaseRemoteConfig.getString("textView_send_text");

    Toast.makeText(this, welcomeMessage,
            Toast.LENGTH_SHORT).show();
}

Toast output:

2

So Toast gets the value from xml/defaults not from the Cloud. It'd be much appreciated if somebody found where I made a mistake.

like image 853
Furetur Avatar asked Mar 21 '17 19:03

Furetur


People also ask

Is Firebase remote config real time?

Using the Remote Config background function triggering provided by Cloud Functions for Firebase along with FCM, you can propagate Remote Config updates in real-time.

How do I get data from Firebase remote config?

Getting started Run the sample on an Android device or emulator. Change one or more parameter values in the Firebase Console (the value of welcome_message , welcome_message_caps , or both). Tap Fetch Remote Config in the app to fetch new parameter values and see the resulting change in the app.

How does Firebase remote configuration work?

Firebase Remote Config is a cloud service that lets you change the behavior and appearance of your app without requiring users to download an app update. When using Remote Config, you create in-app default values that control the behavior and appearance of your app.

Is Firebase remote config down?

Firebase Remote Config is currently experiencing an global issue where write calls to projects that are utilizing Cloud Function integrations may be failing. Elevated failure rate with Firebase Remote Config.


2 Answers

For development testing, specify a cache expiration time of zero to force an immediate fetch:

mFirebaseRemoteConfig.fetch(0) // <- add the zero
        .addOnCompleteListener(this, new OnCompleteListener<Void>() {
            ...
        });
like image 129
Bob Snyder Avatar answered Sep 25 '22 00:09

Bob Snyder


Some tips the helped to me:

  • Don't forget to click "publish changes" in Firebase console after each value update
  • Uninstall and install the App before checking (Firebase may not fetch immediately)
  • Use mFirebaseRemoteConfig.fetch(0)
like image 31
Pavel Poley Avatar answered Sep 23 '22 00:09

Pavel Poley