FirebaseRemoteConfig

public class FirebaseRemoteConfig


Entry point for the Firebase Remote Config 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 Remote Config parameter values available to your app. The singleton also stores values fetched from the Remote Config server until they are made available for use with a call to activate.

Summary

Constants

static final boolean

The static default boolean value for any given key.

static final byte[]

The static default byte array value for any given key.

static final double

The static default double value for any given key.

static final long

The static default long value for any given key.

static final String

The static default string value for any given key.

static final int

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

static final int

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

static final int

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

static final int

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

static final int

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

static final int

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

static final int

Indicates that the value returned is the static default value.

Public methods

@NonNull Task<Boolean>

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

@NonNull ConfigUpdateListenerRegistration

Starts listening for real-time config updates from the Remote Config backend and automatically fetches updates from the RC backend when they are available.

@NonNull Task<FirebaseRemoteConfigInfo>

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

@NonNull Task<Void>

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

@NonNull Task<Void>
fetch(long minimumFetchIntervalInSeconds)

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

@NonNull Task<Boolean>

Asynchronously fetches and then activates the fetched configs.

@NonNull Map<StringFirebaseRemoteConfigValue>

Returns a Map of Firebase Remote Config key value pairs.

boolean

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

double

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

@NonNull FirebaseRemoteConfigInfo

Returns the state of this FirebaseRemoteConfig instance as a FirebaseRemoteConfigInfo.

static @NonNull FirebaseRemoteConfig

Returns a singleton instance of Firebase Remote Config.

static @NonNull FirebaseRemoteConfig

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

@NonNull Set<String>

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

long

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

@NonNull String

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

@NonNull FirebaseRemoteConfigValue

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

@NonNull Task<Void>

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

@NonNull Task<Void>

Asynchronously changes the settings for this FirebaseRemoteConfig instance.

@NonNull Task<Void>

Asynchronously sets default configs using the given Map.

@NonNull Task<Void>
setDefaultsAsync(@XmlRes int resourceId)

Sets default configs using an XML resource.

Extension functions

final @NonNull FirebaseRemoteConfigValue
RemoteConfigKt.get(
    @NonNull FirebaseRemoteConfig receiver,
    @NonNull String key
)

See FirebaseRemoteConfig#getValue

final @NonNull FirebaseRemoteConfigValue
RemoteConfigKt.get(
    @NonNull FirebaseRemoteConfig receiver,
    @NonNull String key
)

This method is deprecated. Migrate to use the KTX API from the main module: https://firebase.google.com/docs/android/kotlin-migration.

final @NonNull Flow<@NonNull ConfigUpdate>
final @NonNull Flow<@NonNull ConfigUpdate>

Constants

DEFAULT_VALUE_FOR_BOOLEAN

public static final boolean DEFAULT_VALUE_FOR_BOOLEAN = false

The static default boolean value for any given key.

DEFAULT_VALUE_FOR_BYTE_ARRAY

public static final byte[] DEFAULT_VALUE_FOR_BYTE_ARRAY

The static default byte array value for any given key.

DEFAULT_VALUE_FOR_DOUBLE

public static final double DEFAULT_VALUE_FOR_DOUBLE = 0.0

The static default double value for any given key.

DEFAULT_VALUE_FOR_LONG

public static final long DEFAULT_VALUE_FOR_LONG = 0

The static default long value for any given key.

DEFAULT_VALUE_FOR_STRING

public static final String DEFAULT_VALUE_FOR_STRING = ""

The static default string value for any given key.

LAST_FETCH_STATUS_FAILURE

public static final int LAST_FETCH_STATUS_FAILURE = 1

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

LAST_FETCH_STATUS_NO_FETCH_YET

public static final int LAST_FETCH_STATUS_NO_FETCH_YET = 0

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

LAST_FETCH_STATUS_SUCCESS

public static final int LAST_FETCH_STATUS_SUCCESS = -1

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

LAST_FETCH_STATUS_THROTTLED

public static final int LAST_FETCH_STATUS_THROTTLED = 2

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

VALUE_SOURCE_DEFAULT

public static final int VALUE_SOURCE_DEFAULT = 1

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

VALUE_SOURCE_REMOTE

public static final int VALUE_SOURCE_REMOTE = 2

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

VALUE_SOURCE_STATIC

public static final int VALUE_SOURCE_STATIC = 0

Indicates that the value returned is the static default value.

Public methods

activate

public @NonNull Task<Booleanactivate()

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

Returns
@NonNull Task<Boolean>

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

addOnConfigUpdateListener

public @NonNull ConfigUpdateListenerRegistration addOnConfigUpdateListener(
    @NonNull ConfigUpdateListener configUpdateListener
)

Starts listening for real-time config updates from the Remote Config backend and automatically fetches updates from the RC backend when they are available.

If a connection to the Remote Config backend is not already open, calling this method will open it. Multiple listeners can be added by calling this method again, but subsequent calls re-use the same connection to the backend.

Note: Real-time Remote Config requires the Firebase Remote Config Realtime API. See the Remote Config Get Started guide to enable the API.

Parameters
@NonNull ConfigUpdateListener configUpdateListener

A ConfigUpdateListener that can be used to respond to config updates when they're fetched.

Returns
@NonNull ConfigUpdateListenerRegistration

A ConfigUpdateListenerRegistration that allows you to remove the added configUpdateListener and close the connection when there are no more listeners.

ensureInitialized

public @NonNull Task<FirebaseRemoteConfigInfoensureInitialized()

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

fetch

public @NonNull Task<Voidfetch()

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.

Note: Also initializes the Firebase installations SDK that creates installation IDs to identify Firebase installations and periodically sends data to Firebase servers. Remote Config requires installation IDs for Fetch requests. To stop the periodic sync, call delete. Sending a Fetch request after deletion will create a new installation ID for this Firebase installation and resume the periodic sync.

Returns
@NonNull Task<Void>

Task representing the fetch call.

fetch

public @NonNull Task<Voidfetch(long minimumFetchIntervalInSeconds)

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.

Note: Also initializes the Firebase installations SDK that creates installation IDs to identify Firebase installations and periodically sends data to Firebase servers. Remote Config requires installation IDs for Fetch requests. To stop the periodic sync, call delete. Sending a Fetch request after deletion will create a new installation ID for this Firebase installation and resume the periodic sync.

Parameters
long minimumFetchIntervalInSeconds

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
@NonNull Task<Void>

Task representing the fetch call.

fetchAndActivate

public @NonNull Task<BooleanfetchAndActivate()

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
@NonNull Task<Boolean>

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.

getAll

public @NonNull Map<StringFirebaseRemoteConfigValuegetAll()

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.

getBoolean

public boolean getBoolean(@NonNull 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, 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
@NonNull String key

A Firebase Remote Config parameter key with a boolean parameter value.

Returns
boolean

boolean representing the value of the Firebase Remote Config parameter with the given key.

getDouble

public double getDouble(@NonNull 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, and the value can be converted into a double.
  3. DEFAULT_VALUE_FOR_DOUBLE.
Parameters
@NonNull String key

A Firebase Remote Config parameter key with a double parameter value.

Returns
double

double representing the value of the Firebase Remote Config parameter with the given key.

getInfo

public @NonNull FirebaseRemoteConfigInfo getInfo()

Returns the state of this FirebaseRemoteConfig instance as a FirebaseRemoteConfigInfo.

getInstance

public static @NonNull FirebaseRemoteConfig getInstance()

Returns a singleton instance of Firebase Remote Config.

FirebaseRemoteConfig uses the default FirebaseApp, throwing an IllegalStateException if one has not been initialized yet.

Note: Also initializes the Firebase installations SDK that creates installation IDs to identify Firebase installations and periodically sends data to Firebase servers. Remote Config requires installation IDs for Fetch requests. To stop the periodic sync, call delete. Sending a Fetch request after deletion will create a new installation ID for this Firebase installation and resume the periodic sync.

Returns
@NonNull FirebaseRemoteConfig

A singleton instance of FirebaseRemoteConfig for the default FirebaseApp.

getInstance

public static @NonNull FirebaseRemoteConfig getInstance(@NonNull FirebaseApp app)

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

getKeysByPrefix

public @NonNull Set<StringgetKeysByPrefix(@NonNull String prefix)

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

Parameters
@NonNull String prefix

The key prefix to look for. If the prefix is empty, all keys are returned.

Returns
@NonNull Set<String>

Set of Remote Config parameter keys that start with the specified prefix.

getLong

public long getLong(@NonNull 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, and the value can be converted into a long.
  3. DEFAULT_VALUE_FOR_LONG.
Parameters
@NonNull String key

A Firebase Remote Config parameter key with a long parameter value.

Returns
long

long representing the value of the Firebase Remote Config parameter with the given key.

getString

public @NonNull String getString(@NonNull 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.
  3. DEFAULT_VALUE_FOR_STRING.
Parameters
@NonNull String key

A Firebase Remote Config parameter key.

Returns
@NonNull String

String representing the value of the Firebase Remote Config parameter with the given key.

getValue

public @NonNull FirebaseRemoteConfigValue getValue(@NonNull 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.
  3. A FirebaseRemoteConfigValue that returns the static value for each type.
Parameters
@NonNull String key

A Firebase Remote Config parameter key.

Returns
@NonNull FirebaseRemoteConfigValue

FirebaseRemoteConfigValue representing the value of the Firebase Remote Config parameter with the given key.

reset

public @NonNull Task<Voidreset()

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

Returns
@NonNull Task<Void>

Task representing the clear call.

setConfigSettingsAsync

public @NonNull Task<VoidsetConfigSettingsAsync(@NonNull FirebaseRemoteConfigSettings settings)

Asynchronously changes the settings for this FirebaseRemoteConfig instance.

Parameters
@NonNull FirebaseRemoteConfigSettings settings

The new settings to be applied.

setDefaultsAsync

public @NonNull Task<VoidsetDefaultsAsync(@NonNull 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
@NonNull Map<StringObject> defaults

Map of key value pairs representing Firebase Remote Config parameter keys and values.

setDefaultsAsync

public @NonNull Task<VoidsetDefaultsAsync(@XmlRes int resourceId)

Sets default configs using an XML resource.

Parameters
@XmlRes int resourceId

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

Extension functions

RemoteConfigKt.get

public final @NonNull FirebaseRemoteConfigValue RemoteConfigKt.get(
    @NonNull FirebaseRemoteConfig receiver,
    @NonNull String key
)

See FirebaseRemoteConfig#getValue

RemoteConfigKt.get

public final @NonNull FirebaseRemoteConfigValue RemoteConfigKt.get(
    @NonNull FirebaseRemoteConfig receiver,
    @NonNull String key
)

See FirebaseRemoteConfig#getValue

Deprecation Notice: The Kotlin extensions (KTX) APIs have been added to their respective main modules, and the Kotlin extension (KTX) APIs in com.google.firebase:firebase-config-ktx are now deprecated. As early as April 2024, we'll no longer release KTX modules. For details, see the FAQ about this initiative.

RemoteConfigKt.getConfigUpdates

public final @NonNull Flow<@NonNull ConfigUpdateRemoteConfigKt.getConfigUpdates(@NonNull FirebaseRemoteConfig receiver)

RemoteConfigKt.getConfigUpdates

public final @NonNull Flow<@NonNull ConfigUpdateRemoteConfigKt.getConfigUpdates(@NonNull FirebaseRemoteConfig receiver)