Go to console

FirebaseRemoteConfig

public class FirebaseRemoteConfig extends Object

Entry point for the Firebase Remote Config (FRC) API.

Callers should first get the singleton object using getInstance(), and then call operations on that singleton object. The singleton contains the complete set of FRC parameter values available to your app. The singleton also caches values fetched from the FRC Server until they are made available for use with a call to activate().

Constant Summary

boolean DEFAULT_VALUE_FOR_BOOLEAN The static default boolean value for any given key.
double DEFAULT_VALUE_FOR_DOUBLE The static default double value for any given key.
long DEFAULT_VALUE_FOR_LONG The static default long value for any given key.
String DEFAULT_VALUE_FOR_STRING The static default string value for any given key.
int LAST_FETCH_STATUS_FAILURE Indicates that the most recent attempt to fetch parameter values from the Firebase Remote Config Server has failed.
int LAST_FETCH_STATUS_NO_FETCH_YET Indicates that the FirebaseRemoteConfig singleton object has not yet attempted to fetch parameter values from the Firebase Remote Config Server.
int LAST_FETCH_STATUS_SUCCESS Indicates that the most recent fetch of parameter values from the Firebase Remote Config Server was completed successfully.
int LAST_FETCH_STATUS_THROTTLED Indicates that the most recent attempt to fetch parameter values from the Firebase Remote Config Server was throttled.
int VALUE_SOURCE_DEFAULT Indicates that the value returned was retrieved from the defaults set by the client.
int VALUE_SOURCE_REMOTE Indicates that the value returned was retrieved from the Firebase Remote Config Server.
int VALUE_SOURCE_STATIC Indicates that the value returned is the static default value.

Field Summary

public static final byte[] DEFAULT_VALUE_FOR_BYTE_ARRAY The static default byte array value for any given key.

Public Method Summary

Task<Boolean>
activate()
Asynchronously activates the most recently fetched configs, so that the fetched key value pairs take effect.
boolean
activateFetched()
This method is deprecated. Use activate() instead.
Task<FirebaseRemoteConfigInfo>
ensureInitialized()
Returns a Task representing the initialization status of this Firebase Remote Config instance.
Task<Void>
fetch()
Starts fetching configs, adhering to the default minimum fetch interval.
Task<Void>
fetch(long cacheExpirationSeconds)
Starts fetching configs, adhering to the specified minimum fetch interval.
Task<Boolean>
fetchAndActivate()
Asynchronously fetches and then activates the fetched configs.
Map<StringFirebaseRemoteConfigValue>
getAll()
Returns a Map of Firebase Remote Config key value pairs.
boolean
getBoolean(String key, String namespace)
Returns the parameter value for the given key in the given namespace as a boolean.
boolean
getBoolean(String key)
Returns the parameter value for the given key as a boolean.
byte[]
getByteArray(String key, String namespace)
Returns the parameter value for the given key in the given namespace as a byte[].
byte[]
getByteArray(String key)
Returns the parameter value for the given key as a byte[].
double
getDouble(String key, String namespace)
Returns the parameter value for the given key in the given namespace as a double.
double
getDouble(String key)
Returns the parameter value for the given key as a double.
FirebaseRemoteConfigInfo
getInfo()
Returns the state of this FirebaseRemoteConfig instance as a FirebaseRemoteConfigInfo.
static FirebaseRemoteConfig
getInstance()
Returns a singleton instance of Firebase Remote Config.
static FirebaseRemoteConfig
getInstance(FirebaseApp app)
Returns an instance of Firebase Remote Config for the given FirebaseApp.
Set<String>
getKeysByPrefix(String prefix, String namespace)
Returns a Set of all Firebase Remote Config parameter keys with the given prefix in the given namespace.
Set<String>
getKeysByPrefix(String prefix)
Returns a Set of all Firebase Remote Config parameter keys with the given prefix.
long
getLong(String key)
Returns the parameter value for the given key as a long.
long
getLong(String key, String namespace)
Returns the parameter value for the given key in the given namespace as a long.
String
getString(String key)
Returns the parameter value for the given key as a String.
String
getString(String key, String namespace)
Returns the parameter value for the given key in the given namespace as a String.
FirebaseRemoteConfigValue
getValue(String key)
Returns the parameter value for the given key as a FirebaseRemoteConfigValue.
FirebaseRemoteConfigValue
getValue(String key, String namespace)
Returns the parameter value for the given key in the given namespace as a FirebaseRemoteConfigValue.
Task<Void>
reset()
Deletes all activated, fetched and defaults configs and resets all Firebase Remote Config settings.
void
setConfigSettings(FirebaseRemoteConfigSettings settings)
Changes the settings for this FirebaseRemoteConfig instance.
void
setDefaults(int resourceId)
Sets default configs using an XML resource.
void
setDefaults(Map<StringObject> defaults, String namespace)
Sets default configs in the given namespace using the given Map.
void
setDefaults(Map<StringObject> defaults)
Sets default configs using the given Map.
void
setDefaults(int resourceId, String namespace)
Set defaults in the given namespace, using an XML resource file.
Task<Void>
setDefaultsAsync(int resourceId)
Sets default configs using an XML resource.
Task<Void>
setDefaultsAsync(Map<StringObject> defaults)
Asynchronously sets default configs using the given Map.

Inherited Method Summary

Constants

public static final boolean DEFAULT_VALUE_FOR_BOOLEAN

The static default boolean value for any given key.

Constant Value: false

public static final double DEFAULT_VALUE_FOR_DOUBLE

The static default double value for any given key.

Constant Value: 0.0

public static final long DEFAULT_VALUE_FOR_LONG

The static default long value for any given key.

Constant Value: 0

public static final String DEFAULT_VALUE_FOR_STRING

The static default string value for any given key.

Constant Value: ""

public static final int LAST_FETCH_STATUS_FAILURE

Indicates that the most recent attempt to fetch parameter values from the Firebase Remote Config Server has failed.

Constant Value: 1

public static final int LAST_FETCH_STATUS_NO_FETCH_YET

Indicates that the FirebaseRemoteConfig singleton object has not yet attempted to fetch parameter values from the Firebase Remote Config Server.

Constant Value: 0

public static final int LAST_FETCH_STATUS_SUCCESS

Indicates that the most recent fetch of parameter values from the Firebase Remote Config Server was completed successfully.

Constant Value: -1

public static final int LAST_FETCH_STATUS_THROTTLED

Indicates that the most recent attempt to fetch parameter values from the Firebase Remote Config Server was throttled.

Constant Value: 2

public static final int VALUE_SOURCE_DEFAULT

Indicates that the value returned was retrieved from the defaults set by the client.

Constant Value: 1

public static final int VALUE_SOURCE_REMOTE

Indicates that the value returned was retrieved from the Firebase Remote Config Server.

Constant Value: 2

public static final int VALUE_SOURCE_STATIC

Indicates that the value returned is the static default value.

Constant Value: 0

Fields

public static final byte[] DEFAULT_VALUE_FOR_BYTE_ARRAY

The static default byte array value for any given key.

Public Methods

public Task<Boolean> activate ()

Asynchronously activates the most recently fetched configs, so that the fetched key value pairs take effect.

Returns
  • Task with a true result if the current call activated the fetched configs; if the fetched configs were already activated by a previous call, returns a Task with a false result.

public boolean activateFetched ()

This method is deprecated.
Use activate() instead.

Activates the most recently fetched configs, so that the fetched key value pairs take effect.

Returns
  • True if the current call activated the fetched configs; false if the fetched configs were already activated by a previous call.

public Task<FirebaseRemoteConfigInfo> ensureInitialized ()

Returns a Task representing the initialization status of this Firebase Remote Config instance.

public Task<Void> fetch ()

Starts fetching configs, adhering to the default minimum fetch interval.

The fetched configs only take effect after the next activate() call.

Depending on the time elapsed since the last fetch from the Firebase Remote Config backend, configs are either served from local storage, or fetched from the backend. The default minimum fetch interval can be set with FirebaseRemoteConfigSettings.Builder#setMinimumFetchIntervalInSeconds(long); the static default is 12 hours.

To identify the current app instance, the fetch request creates a Firebase Instance ID token, which periodically sends data to the Firebase backend. To stop the periodic sync, call deleteInstanceId(). To create a new token and resume the periodic sync, call fetchConfig again.

Returns
  • Task representing the fetch call.

public Task<Void> fetch (long cacheExpirationSeconds)

Starts fetching configs, adhering to the specified minimum fetch interval.

The fetched configs only take effect after the next activate() call.

Depending on the time elapsed since the last fetch from the Firebase Remote Config backend, configs are either served from local storage, or fetched from the backend.

To identify the current app instance, the fetch request creates a Firebase Instance ID token, which periodically sends data to the Firebase backend. To stop the periodic sync, call deleteInstanceId(). To create a new token and resume the periodic sync, call fetchConfig again.

Parameters
cacheExpirationSeconds If configs in the local storage were fetched more than this many seconds ago, configs are served from the backend instead of local storage.
Returns
  • Task representing the fetch call.

public Task<Boolean> fetchAndActivate ()

Asynchronously fetches and then activates the fetched configs.

If the time elapsed since the last fetch from the Firebase Remote Config backend is more than the default minimum fetch interval, configs are fetched from the backend.

After the fetch is complete, the configs are activated so that the fetched key value pairs take effect.

Returns
  • Task with a true result if the current call activated the fetched configs; if no configs were fetched from the backend and the local fetched configs have already been activated, returns a Task with a false result.

public Map<StringFirebaseRemoteConfigValue> getAll ()

Returns a Map of Firebase Remote Config key value pairs.

Evaluates the values of the parameters in the following order:

  1. The activated value, if the last successful activate() contained the key.
  2. The default value, if the key was set with setDefaultsAsync(int).

public boolean getBoolean (String key, String namespace)

Returns the parameter value for the given key in the given namespace as a boolean.

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key, and the value can be converted into a boolean.
  2. The default value, if the key was set with setDefaultsAsync(int), and the value can be converted into a boolean.
  3. DEFAULT_VALUE_FOR_BOOLEAN.

"1", "true", "t", "yes", "y", and "on" are strings that are interpreted (case insensitive) as true, and "0", "false", "f", "no", "n", "off", and empty string are interpreted (case insensitive) as false.

Parameters
key A Firebase Remote Config parameter key with a boolean parameter value.
namespace
Returns
  • boolean representing the value of the Firebase Remote Config parameter with the given key in the given namespace.

public boolean getBoolean (String key)

Returns the parameter value for the given key as a boolean.

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key, and the value can be converted into a boolean.
  2. The default value, if the key was set with setDefaultsAsync(int), and the value can be converted into a boolean.
  3. DEFAULT_VALUE_FOR_BOOLEAN.

"1", "true", "t", "yes", "y", and "on" are strings that are interpreted (case insensitive) as true, and "0", "false", "f", "no", "n", "off", and empty string are interpreted (case insensitive) as false.

Parameters
key A Firebase Remote Config parameter key with a boolean parameter value.
Returns
  • boolean representing the value of the Firebase Remote Config parameter with the given key.

public byte[] getByteArray (String key, String namespace)

Returns the parameter value for the given key in the given namespace as a byte[].

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key.
  2. The default value, if the key was set with setDefaultsAsync(int).
  3. DEFAULT_VALUE_FOR_BYTE_ARRAY.
Parameters
key A Firebase Remote Config parameter key.
namespace
Returns
  • byte[] representing the value of the Firebase Remote Config parameter with the given key in the given namespace.

public byte[] getByteArray (String key)

Returns the parameter value for the given key as a byte[].

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key.
  2. The default value, if the key was set with setDefaultsAsync(int).
  3. DEFAULT_VALUE_FOR_BYTE_ARRAY.
Parameters
key A Firebase Remote Config parameter key.
Returns
  • byte[] representing the value of the Firebase Remote Config parameter with the given key.

public double getDouble (String key, String namespace)

Returns the parameter value for the given key in the given namespace as a double.

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key, and the value can be converted into a double.
  2. The default value, if the key was set with setDefaultsAsync(int), and the value can be converted into a double.
  3. DEFAULT_VALUE_FOR_DOUBLE.
Parameters
key A Firebase Remote Config parameter key with a double parameter value.
namespace
Returns
  • double representing the value of the Firebase Remote Config parameter with the given key in the given namespace.

public double getDouble (String key)

Returns the parameter value for the given key as a double.

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key, and the value can be converted into a double.
  2. The default value, if the key was set with setDefaultsAsync(int), and the value can be converted into a double.
  3. DEFAULT_VALUE_FOR_DOUBLE.
Parameters
key A Firebase Remote Config parameter key with a double parameter value.
Returns
  • double representing the value of the Firebase Remote Config parameter with the given key.

public FirebaseRemoteConfigInfo getInfo ()

Returns the state of this FirebaseRemoteConfig instance as a FirebaseRemoteConfigInfo.

public static FirebaseRemoteConfig getInstance ()

Returns a singleton instance of Firebase Remote Config.

FirebaseRemoteConfig uses the default FirebaseApp, so if no FirebaseApp has been initialized yet, this method throws an IllegalStateException.

To identify the current app instance, the fetch request creates a Firebase Instance ID token, which periodically sends data to the Firebase backend. To stop the periodic sync, call deleteInstanceId(). To create a new token and resume the periodic sync, call fetchConfig again.

Returns

public static FirebaseRemoteConfig getInstance (FirebaseApp app)

Returns an instance of Firebase Remote Config for the given FirebaseApp.

public Set<String> getKeysByPrefix (String prefix, String namespace)

Returns a Set of all Firebase Remote Config parameter keys with the given prefix in the given namespace.

Parameters
prefix The key prefix to look for. If the prefix is empty, all keys are returned.
namespace
Returns
  • Set of Remote Config parameter keys in the given namespace that start with the specified prefix.

public Set<String> getKeysByPrefix (String prefix)

Returns a Set of all Firebase Remote Config parameter keys with the given prefix.

Parameters
prefix The key prefix to look for. If the prefix is empty, all keys are returned.
Returns
  • Set of Remote Config parameter keys that start with the specified prefix.

public long getLong (String key)

Returns the parameter value for the given key as a long.

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key, and the value can be converted into a long.
  2. The default value, if the key was set with setDefaultsAsync(int), and the value can be converted into a long.
  3. DEFAULT_VALUE_FOR_LONG.
Parameters
key A Firebase Remote Config parameter key with a long parameter value.
Returns
  • long representing the value of the Firebase Remote Config parameter with the given key.

public long getLong (String key, String namespace)

Returns the parameter value for the given key in the given namespace as a long.

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key, and the value can be converted into a long.
  2. The default value, if the key was set with setDefaultsAsync(int), and the value can be converted into a long.
  3. DEFAULT_VALUE_FOR_LONG.
Parameters
key A Firebase Remote Config parameter key with a long parameter value.
namespace
Returns
  • long representing the value of the Firebase Remote Config parameter with the given key in the given namespace.

public String getString (String key)

Returns the parameter value for the given key as a String.

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key.
  2. The default value, if the key was set with setDefaultsAsync(int).
  3. DEFAULT_VALUE_FOR_STRING.
Parameters
key A Firebase Remote Config parameter key.
Returns
  • String representing the value of the Firebase Remote Config parameter with the given key.

public String getString (String key, String namespace)

Returns the parameter value for the given key in the given namespace as a String.

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key.
  2. The default value, if the key was set with setDefaultsAsync(int).
  3. DEFAULT_VALUE_FOR_STRING.
Parameters
key A Firebase Remote Config parameter key.
namespace

public FirebaseRemoteConfigValue getValue (String key)

Returns the parameter value for the given key as a FirebaseRemoteConfigValue.

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key.
  2. The default value, if the key was set with setDefaultsAsync(int).
  3. A FirebaseRemoteConfigValue that returns the static value for each type.
Parameters
key A Firebase Remote Config parameter key.
Returns

public FirebaseRemoteConfigValue getValue (String key, String namespace)

Returns the parameter value for the given key in the given namespace as a FirebaseRemoteConfigValue.

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key.
  2. The default value, if the key was set with setDefaultsAsync(int).
  3. A FirebaseRemoteConfigValue that returns the static value for each type.
Parameters
key A Firebase Remote Config parameter key.
namespace
Returns
  • A FirebaseRemoteConfigValue representing the value of the Firebase Remote Config parameter with the given key in the given namespace.

public Task<Void> reset ()

Deletes all activated, fetched and defaults configs and resets all Firebase Remote Config settings.

Returns
  • Task representing the clear call.

public void setConfigSettings (FirebaseRemoteConfigSettings settings)

Changes the settings for this FirebaseRemoteConfig instance.

Parameters
settings The new settings to be applied. If null, all settings are cleared.

public void setDefaults (int resourceId)

Sets default configs using an XML resource.

Parameters
resourceId Id for the XML resource, which should be in your application's res/xml folder.

public void setDefaults (Map<StringObject> defaults, String namespace)

Sets default configs in the given namespace using the given Map.

The values in defaults must be one of the following types:

  • Long
  • String
  • Double
  • byte[]
  • Boolean
Parameters
defaults Map of key value pairs representing Firebase Remote Config parameter keys and values.
namespace The namespace in which to set the defaults.

public void setDefaults (Map<StringObject> defaults)

Sets default configs using the given Map.

The values in defaults must be one of the following types:

  • Long
  • String
  • Double
  • byte[]
  • Boolean
Parameters
defaults Map of key value pairs representing Firebase Remote Config parameter keys and values.

public void setDefaults (int resourceId, String namespace)

Set defaults in the given namespace, using an XML resource file.

Parameters
resourceId Id for the XML resource, which should be in your application's * res/xml folder.
namespace The namespace in which to set the defaults.

public Task<Void> setDefaultsAsync (int resourceId)

Sets default configs using an XML resource.

Parameters
resourceId Id for the XML resource, which should be in your application's res/xml folder.

public Task<Void> setDefaultsAsync (Map<StringObject> defaults)

Asynchronously sets default configs using the given Map.

The values in defaults must be one of the following types:

  • byte[]
  • Boolean
  • Double
  • Long
  • String
Parameters
defaults Map of key value pairs representing Firebase Remote Config parameter keys and values.