0

What I am trying to do is to save the colorPrimay, colorDarkPrimary and so on, values in RemoteConfig of Firebase so that I could able to change the colors of the apps from remote config and I did following

UPDATE: What I am trying to do is to save the colorPrimay, colorDarkPrimary and so on, values in RemoteConfig of Firebase so that I could able to change the colors of the apps from remote confi. How could I do that?

UPDATE:

What I have tried is like

<--!remote_config_default.xml!-->


<defaultsMap>
<entry>
    <key>primaryColor</key>
    <value>#9c27b0</value>
</entry>
<entry>
    <key>colorPrimaryDark</key>
    <value>#7b1fa2</value>
</entry>
<entry>
    <key>colorAccent</key>
    <value>#FF4081</value>
</entry>
<entry>welcomeMessage</entry>
<value>Connection Failed</value>

And fetch like this

    void applyRemoteConfig() {
        mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
        mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_default);
        // cacheExpirationSeconds is set to cacheExpiration here, indicating that any previously
// fetched and cached config would be considered expired because it would have been fetched
// more than cacheExpiration seconds ago. Thus the next fetch would go to the server unless
// throttling is in progress. The default expiration duration is 43200 (12 hours).
        int cacheExpiration = 1000;
        final String TAG = "Riddles";
        mFirebaseRemoteConfig.fetch(cacheExpiration)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()) {
                            Log.d(TAG, "Fetch Succeeded");
                            // Once the config is successfully fetched it must be activated before newly fetched
                            // values are returned.
                            mFirebaseRemoteConfig.activateFetched();
                        } else {
                            Log.d(TAG, "Fetch failed");
                            String message = mFirebaseRemoteConfig.getString("welcomeMessage");
                            displayWelcomeMessage(message);
                            Log.d(TAG, message);
                        }
                    }
                });

        String message = mFirebaseRemoteConfig.getString("welcomeMessage");
        displayWelcomeMessage(message);
        Log.d(TAG, message);


    }

But the

mFirebaseRemoteConfig.getString("colorPrimary");

mFirebaseRemoteConfig.getString("colorDarkPrimary");

mFirebaseRemoteConfig.getString("welcomeMessage");

Are returning Null.

Ngima Sherpa
  • 1,397
  • 1
  • 13
  • 34

1 Answers1

2

You could add this to your remote config file.

<!-- color entries -->
    <entry>
        <key>color_primary</key>
        <value>#3F51B5</value>
    </entry>
    <entry>
        <key>color_primary_dark</key>
        <value>#303F9F</value>
    </entry>  

To change your app's colour dynamically, have a flag supplied by remote config as well and change it using fetch(). For elaborate implementations refer to this.

not_again_stackoverflow
  • 1,285
  • 1
  • 13
  • 27