FirebaseRemoteConfig

public class FirebaseRemoteConfig extends Object

Entry point for FirebaseRemoteConfig. Callers should first get the singleton object using getInstance(), and then call the operations on that singleton object. The singleton object contains the complete set of Remote Config parameter values available to your app, including the Active Config and Default Config. This object also caches values fetched from the Remote Config Server until they are copied to the Active Config by calling activateFetched().

Constant Summary

boolean DEFAULT_VALUE_FOR_BOOLEAN
double DEFAULT_VALUE_FOR_DOUBLE
long DEFAULT_VALUE_FOR_LONG
String DEFAULT_VALUE_FOR_STRING
int LAST_FETCH_STATUS_FAILURE Indicates that the most recent attempt to fetch parameter values from the 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 Remote Config Server.
int LAST_FETCH_STATUS_SUCCESS Indicates that the most recent fetch of parameter values from the Remote Config Server was completed successfully.
int LAST_FETCH_STATUS_THROTTLED Indicates that the most recent attempt to fetch parameter values from the Remote Config Server was throttled.
int VALUE_SOURCE_DEFAULT Indicates that the value returned was retrieved from the Default Config.
int VALUE_SOURCE_REMOTE Indicates that the value returned was retrieved from the 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

Public Method Summary

boolean
activateFetched()
Activates the Fetched Config, so that the fetched key-values take effect.
Task<Void>
fetch(long cacheExpirationSeconds)
Fetches parameter values for your app.
Task<Void>
fetch()
Fetches parameter values for your app.
boolean
getBoolean(String key, String namespace)
Gets the value corresponding to the specified key, as a boolean, in the specified namespace.
boolean
getBoolean(String key)
Gets the value corresponding to the specified key, as a boolean.
byte[]
getByteArray(String key, String namespace)
Gets the value corresponding to the specified key, in the specified namespace, as a byte array.
byte[]
getByteArray(String key)
Gets the value corresponding to the specified key, as a byte array.
double
getDouble(String key, String namespace)
Gets the value corresponding to the specified key, in the specified namespace, as a double.
double
getDouble(String key)
Gets the value corresponding to the specified key, as a double.
FirebaseRemoteConfigInfo
getInfo()
Gets the current state of the FirebaseRemoteConfig singleton object.
static FirebaseRemoteConfig
getInstance()
Getter for the singleton FirebaseRemoteConfig object.
Set<String>
getKeysByPrefix(String prefix, String namespace)
Gets the set of keys that start with the given prefix, in the given namespace.
Set<String>
getKeysByPrefix(String prefix)
Gets the set of keys that start with the given prefix.
long
getLong(String key)
Gets the value corresponding to the specified key, as a long.
long
getLong(String key, String namespace)
Gets the value corresponding to the specified key, in the specified namespace, as a long.
String
getString(String key)
Gets the value corresponding to the specified key, as a String.
String
getString(String key, String namespace)
Gets value as a string corresponding to the specified key in the specified namespace.
FirebaseRemoteConfigValue
getValue(String key)
Gets the FirebaseRemoteConfigValue corresponding to the specified key.
FirebaseRemoteConfigValue
getValue(String key, String namespace)
Gets the FirebaseRemoteConfigValue corresponding to the specified key.
void
setConfigSettings(FirebaseRemoteConfigSettings settings)
Changes the settings for the FirebaseRemoteConfig object's operations, such as turning the developer mode on.
void
setDefaults(int resourceId)
Sets defaults in the default namespace, using an XML resource.
void
setDefaults(Map<StringObject> defaults, String namespace)
Sets defaults in the default namespace.
void
setDefaults(int resourceId, String namespace)
Set defaults in the given namespace, using an XML resource file.
void
setDefaults(Map<StringObject> defaults)
Sets defaults in the default namespace.

Inherited Method Summary

Constants

public static final boolean DEFAULT_VALUE_FOR_BOOLEAN

Constant Value: false

public static final double DEFAULT_VALUE_FOR_DOUBLE

Constant Value: 0.0

public static final long DEFAULT_VALUE_FOR_LONG

Constant Value: 0

public static final String DEFAULT_VALUE_FOR_STRING

Constant Value: ""

public static final int LAST_FETCH_STATUS_FAILURE

Indicates that the most recent attempt to fetch parameter values from the 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 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 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 Remote Config Server was throttled.

Constant Value: 2

public static final int VALUE_SOURCE_DEFAULT

Indicates that the value returned was retrieved from the Default Config.

Constant Value: 1

public static final int VALUE_SOURCE_REMOTE

Indicates that the value returned was retrieved from the 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

Public Methods

public boolean activateFetched ()

Activates the Fetched Config, so that the fetched key-values take effect.

Returns
  • true if there was a Fetched Config, and it was activated. false if no Fetched Config was found, or the Fetched Config was already activated.

public Task<Void> fetch (long cacheExpirationSeconds)

Fetches parameter values for your app. Configuration values may be served from the Default Config (local cache) or from the Remote Config Server, depending on how much time has elapsed since parameter values were last fetched from the Remote Config server. This method lets the caller specify the cache expiration in seconds.

Parameters
cacheExpirationSeconds If the data in the cache was fetched no longer than this many seconds ago, this method will return the cached data. If not, a fetch from the Remote Config Server will be attempted.
Returns
  • A Task object to track the fetch result.

public Task<Void> fetch ()

Fetches parameter values for your app. Parameter values may be from the Default Config (local cache), or from the Remote Config Server, depending on how much time has elapsed since parameter values were last fetched from the Remote Config server. This method uses the default cache expiration of 12 hours.

Returns
  • A Task object to track the fetch result.

public boolean getBoolean (String key, String namespace)

Gets the value corresponding to the specified key, as a boolean, in the specified namespace.

Parameters
key The Remote Config parameter key to look up.
namespace The namespace in which to look up the key.
Returns
  • Value as a boolean if a value corresponding to the look up key was present and could be converted to a boolean; default (if set) or static default value otherwise.

    "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.

public boolean getBoolean (String key)

Gets the value corresponding to the specified key, as a boolean.

This method uses the default namespace. To query in another namespace, use the getBoolean(String, String) method.

Parameters
key The Remote Config parameter key to look up.
Returns
  • Value as a boolean if a value corresponding to the look up key was present and could be converted to a boolean; default (if set) or static default value otherwise.

    "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.

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

Gets the value corresponding to the specified key, in the specified namespace, as a byte array.

Parameters
key The Remote Config parameter key to look up.
namespace The namespace in which to look up the key.
Returns
  • Value as a byte array if a value corresponding to the look up key was present; default (if set) or static default value otherwise.

public byte[] getByteArray (String key)

Gets the value corresponding to the specified key, as a byte array.

This method uses the default namespace. To query in another namespace, use the getByteArray(String, String) method.

Parameters
key The Remote Config parameter key to look up.
Returns
  • Value as a byte array if a value corresponding to the look up key was present; default (if set) or static default value otherwise.

public double getDouble (String key, String namespace)

Gets the value corresponding to the specified key, in the specified namespace, as a double.

Parameters
key The Remote Config parameter key to look up.
namespace The namespace in which to look up the key.
Returns
  • Value as a double if a value corresponding to the look up key was present and could be converted to a double; default (if set) or static default value otherwise.

public double getDouble (String key)

Gets the value corresponding to the specified key, as a double.

This method uses the default namespace. To query in another namespace, use getDouble(String, String).

Parameters
key The Remote Config parameter key to look up.
Returns
  • Value as a double if a value corresponding to the look up key was present and could be converted to a double; default (if set) or static default value otherwise.

public FirebaseRemoteConfigInfo getInfo ()

Gets the current state of the FirebaseRemoteConfig singleton object.

Returns

public static FirebaseRemoteConfig getInstance ()

Getter for the singleton FirebaseRemoteConfig object. Clients start by getting this object, and then call all of the FirebaseRemoteConfig API methods on this object.

Note: If you test your app using StrictMode, note that the initial getInstance() call on app creation reads from a local file. To avoid StrictMode disk read errors, this initial call should not be made on the UI thread. All subsequent getInstance() calls are safe on the UI thread, because they only read from memory. You should never leave StrictMode enabled in applications distributed on Google Play.

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

Returns
  • Initialized FirebaseRemoteConfig singleton object.

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

Gets the set of keys that start with the given prefix, in the given namespace.

Parameters
prefix The key prefix to look for. If empty or null, this method will return all keys in the given namespace.
namespace The namespace in which to look up the keys.
Returns
  • Set of Remote Config parameter keys that start with the specified prefix. Will return an empty set if there are no keys with the given prefix.

public Set<String> getKeysByPrefix (String prefix)

Gets the set of keys that start with the given prefix.

This method uses the default namespace. To query in another namespace, use getKeysByPrefix(String, String).

Parameters
prefix The key prefix to look for. If empty or null, this method will return all keys.
Returns
  • Set of Remote Config parameter keys that start with the specified prefix. Will return an empty set if there are no keys with the given prefix.

public long getLong (String key)

Gets the value corresponding to the specified key, as a long.

This method uses the default namespace. To query in another namespace, use getLong(String, String).

Parameters
key The Remote Config parameter key to look up.
Returns
  • Value as a long if a value corresponding to the look up key was present and could be converted to a long; default (if set) or static default value otherwise.

public long getLong (String key, String namespace)

Gets the value corresponding to the specified key, in the specified namespace, as a long.

Parameters
key The Remote Config parameter config key to look up.
namespace The namespace in which to look up the key.
Returns
  • Value as a long if a value corresponding to the look up key was present and could be converted to a long; default (if set) or static default value otherwise.

public String getString (String key)

Gets the value corresponding to the specified key, as a String.

This method uses the default namespace. To query in another namespace, use the getString(String, String) method.

Parameters
key The Remote Config parameter key to look up.
Returns
  • Value as a String if a value corresponding to the look up key was present; default (if set) or static default value otherwise.

public String getString (String key, String namespace)

Gets value as a string corresponding to the specified key in the specified namespace.

Parameters
key The Remote Config parameter key to look up.
namespace The namespace in which to look up the key.
Returns
  • Value as a string if a value corresponding to the look up key was present and could be converted to a string; default (if set) or static default value otherwise.

public FirebaseRemoteConfigValue getValue (String key)

Gets the FirebaseRemoteConfigValue corresponding to the specified key.

This method uses the default namespace. To query in another namespace, use getValue(String, String).

Parameters
key The Remote Config parameter key to look up.
Returns

public FirebaseRemoteConfigValue getValue (String key, String namespace)

Gets the FirebaseRemoteConfigValue corresponding to the specified key.

Parameters
key The Remote Config parameter key to look up.
namespace The namespace in which to look up the key.
Returns

public void setConfigSettings (FirebaseRemoteConfigSettings settings)

Changes the settings for the FirebaseRemoteConfig object's operations, such as turning the developer mode on.

Parameters
settings The new settings to be applied. If null is passed, it will clear all current settings.

public void setDefaults (int resourceId)

Sets defaults in the default namespace, 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 defaults in the default namespace.

Parameters
defaults Key value map to be used for setting the defaults. The values in this map should be one of the types Long, String, Double, byte[], or Boolean.
namespace The namespace in which to set the defaults.

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 void setDefaults (Map<StringObject> defaults)

Sets defaults in the default namespace. To set defaults in a different namespace, use setDefaults(java.util.Map, String).

Parameters
defaults Key value map to be used for setting the defaults. The values in this map should be one of the types Long, String, Double, byte[], or Boolean.

Send feedback about...

Need help? Visit our support page.