FirebaseRemoteConfig

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

const Boolean

The static default boolean value for any given key.

const ByteArray<Byte>!

The static default byte array value for any given key.

const Double

The static default double value for any given key.

const Long

The static default long value for any given key.

const String!

The static default string value for any given key.

const Int

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

Indicates that the value returned is the static default value.

Public functions

Task<Boolean!>

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

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.

Task<FirebaseRemoteConfigInfo!>

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

Task<Void!>

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

Task<Void!>
fetch(minimumFetchIntervalInSeconds: Long)

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

Task<Boolean!>

Asynchronously fetches and then activates the fetched configs.

(Mutable)Map<String!, FirebaseRemoteConfigValue!>

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.

FirebaseRemoteConfigInfo

Returns the state of this FirebaseRemoteConfig instance as a FirebaseRemoteConfigInfo.

java-static FirebaseRemoteConfig

Returns a singleton instance of Firebase Remote Config.

java-static FirebaseRemoteConfig

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

(Mutable)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.

String

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

FirebaseRemoteConfigValue

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

Task<Void!>

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

Task<Void!>

Asynchronously changes the settings for this FirebaseRemoteConfig instance.

Task<Void!>

Asynchronously sets default configs using the given Map.

Task<Void!>
setDefaultsAsync(resourceId: @XmlRes Int)

Sets default configs using an XML resource.

Extension functions

operator FirebaseRemoteConfigValue

See FirebaseRemoteConfig#getValue

operator FirebaseRemoteConfigValue

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

Extension properties

Flow<ConfigUpdate>

Starts listening for config updates from the Remote Config backend and emits ConfigUpdates via a Flow.

Flow<ConfigUpdate>

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

Constants

DEFAULT_VALUE_FOR_BOOLEAN

const val DEFAULT_VALUE_FOR_BOOLEAN = false: Boolean

The static default boolean value for any given key.

DEFAULT_VALUE_FOR_BYTE_ARRAY

const val DEFAULT_VALUE_FOR_BYTE_ARRAYByteArray<Byte>!

The static default byte array value for any given key.

DEFAULT_VALUE_FOR_DOUBLE

const val DEFAULT_VALUE_FOR_DOUBLE = 0.0: Double

The static default double value for any given key.

DEFAULT_VALUE_FOR_LONG

const val DEFAULT_VALUE_FOR_LONG = 0: Long

The static default long value for any given key.

DEFAULT_VALUE_FOR_STRING

const val DEFAULT_VALUE_FOR_STRING = "": String!

The static default string value for any given key.

LAST_FETCH_STATUS_FAILURE

const val LAST_FETCH_STATUS_FAILURE = 1: Int

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

LAST_FETCH_STATUS_NO_FETCH_YET

const val LAST_FETCH_STATUS_NO_FETCH_YET = 0: Int

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

LAST_FETCH_STATUS_SUCCESS

const val LAST_FETCH_STATUS_SUCCESS = -1: Int

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

LAST_FETCH_STATUS_THROTTLED

const val LAST_FETCH_STATUS_THROTTLED = 2: Int

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

VALUE_SOURCE_DEFAULT

const val VALUE_SOURCE_DEFAULT = 1: Int

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

VALUE_SOURCE_REMOTE

const val VALUE_SOURCE_REMOTE = 2: Int

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

VALUE_SOURCE_STATIC

const val VALUE_SOURCE_STATIC = 0: Int

Indicates that the value returned is the static default value.

Public functions

activate

fun activate(): Task<Boolean!>

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

Returns
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

fun addOnConfigUpdateListener(configUpdateListener: ConfigUpdateListener): 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.

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
configUpdateListener: ConfigUpdateListener

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

Returns
ConfigUpdateListenerRegistration

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

ensureInitialized

fun ensureInitialized(): Task<FirebaseRemoteConfigInfo!>

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

fetch

fun fetch(): Task<Void!>

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
Task<Void!>

Task representing the fetch call.

fetch

fun fetch(minimumFetchIntervalInSeconds: Long): Task<Void!>

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
minimumFetchIntervalInSeconds: Long

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<Void!>

Task representing the fetch call.

fetchAndActivate

fun fetchAndActivate(): Task<Boolean!>

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

fun getAll(): (Mutable)Map<String!, FirebaseRemoteConfigValue!>

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

fun getBoolean(key: String): Boolean

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
key: String

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

fun getDouble(key: String): Double

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
key: String

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

fun getInfo(): FirebaseRemoteConfigInfo

Returns the state of this FirebaseRemoteConfig instance as a FirebaseRemoteConfigInfo.

getInstance

java-static fun getInstance(): FirebaseRemoteConfig

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
FirebaseRemoteConfig

A singleton instance of FirebaseRemoteConfig for the default FirebaseApp.

getInstance

java-static fun getInstance(app: FirebaseApp): FirebaseRemoteConfig

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

getKeysByPrefix

fun getKeysByPrefix(prefix: String): (Mutable)Set<String!>

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

Parameters
prefix: String

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

Returns
(Mutable)Set<String!>

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

getLong

fun getLong(key: String): Long

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
key: String

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

fun getString(key: String): String

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
key: String

A Firebase Remote Config parameter key.

Returns
String

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

getValue

fun getValue(key: String): FirebaseRemoteConfigValue

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
key: String

A Firebase Remote Config parameter key.

Returns
FirebaseRemoteConfigValue

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

reset

fun reset(): Task<Void!>

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

Returns
Task<Void!>

Task representing the clear call.

setConfigSettingsAsync

fun setConfigSettingsAsync(settings: FirebaseRemoteConfigSettings): Task<Void!>

Asynchronously changes the settings for this FirebaseRemoteConfig instance.

Parameters
settings: FirebaseRemoteConfigSettings

The new settings to be applied.

setDefaultsAsync

fun setDefaultsAsync(defaults: (Mutable)Map<String!, Any!>): Task<Void!>

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: (Mutable)Map<String!, Any!>

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

setDefaultsAsync

fun setDefaultsAsync(resourceId: @XmlRes Int): Task<Void!>

Sets default configs using an XML resource.

Parameters
resourceId: @XmlRes Int

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

Extension functions

get

operator fun FirebaseRemoteConfig.get(key: String): FirebaseRemoteConfigValue

See FirebaseRemoteConfig#getValue

get

operator fun FirebaseRemoteConfig.get(key: String): FirebaseRemoteConfigValue

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.

Extension properties

configUpdates

val FirebaseRemoteConfig.configUpdatesFlow<ConfigUpdate>

Starts listening for config updates from the Remote Config backend and emits ConfigUpdates via a Flow. See FirebaseRemoteConfig.addOnConfigUpdateListener for more information.

  • When the returned flow starts being collected, an ConfigUpdateListener will be attached.

  • When the flow completes, the listener will be removed. If there are no attached listeners, the connection to the Remote Config backend will be closed.

configUpdates

val FirebaseRemoteConfig.configUpdatesFlow<ConfigUpdate>

Starts listening for config updates from the Remote Config backend and emits ConfigUpdates via a Flow. See FirebaseRemoteConfig.addOnConfigUpdateListener for more information.

  • When the returned flow starts being collected, an ConfigUpdateListener will be attached.

  • When the flow completes, the listener will be removed. If there are no attached listeners, the connection to the Remote Config backend will be closed.

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.