B4A Library Firebase RemoteConfig

This library allows you to use Firebase RemoteConfig to your app.

Requirements:
- B4A 6+
- To use this library you need to Setup your app to use Firebase-Services first.

Go to the Firebase console and setup remoteconfig

remoteconfig5557.png



RemoteConfig
Author:
DonManfred (wrapper)
Version: 2.50
  • RemoteConfig
    Events:
    • onFetchComplete (success As Boolean)
  • Fields:
    • DEFAULT_VALUE_FOR_BOOLEAN As Boolean
    • DEFAULT_VALUE_FOR_DOUBLE As Double
    • DEFAULT_VALUE_FOR_LONG As Long
    • DEFAULT_VALUE_FOR_STRING As String
    • LAST_FETCH_STATUS_FAILURE As Int
    • LAST_FETCH_STATUS_NO_FETCH_YET As Int
    • LAST_FETCH_STATUS_SUCCESS As Int
    • LAST_FETCH_STATUS_THROTTLED As Int
    • VALUE_SOURCE_DEFAULT As Int
    • VALUE_SOURCE_REMOTE As Int
    • VALUE_SOURCE_STATIC As Int
  • Methods:
    • Defaults (defaults As Map)
    • Initialize (EventName As String)
    • IsInitialized As Boolean
    • activateFetched As Boolean
      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.
      Return type: @return:
    • fetch (cacheExpiration As Int)
    • getBoolean (key As String) As Boolean
      Gets the value corresponding to the specified key,
      as a boolean.
    • getBoolean2 (key As String, namespace As String) As Boolean
      Gets the value corresponding to the specified key,
      as a boolean, in the specified namespace.
    • getByteArray (key As String) As Byte[]
      Gets the value corresponding to the specified
      key as a byte array.
      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.
    • getByteArray2 (key As String, namespace As String) As Byte[]
      Gets the value corresponding to the specified
      key, in the specified namespace, as a byte array.
      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.
    • getDouble (key As String) As Double
      Gets the value corresponding to the specified
      key, in the specified namespace, as a double.
      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.
    • getDouble2 (key As String, namespace As String) As Double
      Gets the value corresponding to the specified
      key as a double.
      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.
    • getLong (key As String) As Long
      Gets the value corresponding to the
      specified key, as a long.

      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.
    • getLong2 (key As String, namespace As String) As Long
      Gets the value corresponding to the specified
      key, in the specified namespace, as a long.
    • getString (key As String) As String
      Gets the value corresponding to
      the specified key, as a string.

      returns alue 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.
    • getString2 (key As String, namespace As String) As String
      Gets value as a string corresponding
      to the specified key in the specified namespace.
      returns alue 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.
    • getValue (key As String) As FirebaseRemoteConfigValue
      Gets the FirebaseRemoteConfigValue
      corresponding to the specified key.
    • getValue2 (key As String, namespace As String) As FirebaseRemoteConfigValue
    • setDefaults2 (defaults As Map, namespace As String)
  • Properties:
    • ConfigSettings As FirebaseRemoteConfigSettings [write only]
      Changes the settings for the FirebaseRemoteConfig
      object's operations, such as turning the developer mode on.
    • Info As FirebaseRemoteConfigInfo [read only]
      Gets the current state of the
      FirebaseRemoteConfig singleton object.
      returns A FirebaseRemoteConfigInfo wrapping the current state.
  • RemoteConfigValue
    Methods:
    • Initialize (cfg As FirebaseRemoteConfigValue)
    • IsInitialized As Boolean
    • asBoolean As Boolean
    • asByteArray As Byte[]
    • asDouble As Double
    • asLong As Long
    • asString As String
  • Properties:
    • Source As Int [read only]
      VALUE_SOURCE_REMOTE if the value was retrieved
      from the server, VALUE_SOURCE_DEFAULT if the
      value was set as a default, or VALUE_SOURCE_STATIC
      if no value was found and a static default
      value was returned instead.


B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim cfg As RemoteConfig
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    cfg.Initialize("Config")
    cfg.Defaults(CreateMap("Month": 1, "loading_phrase": "Hallo world!"))
    Log("loading_phrase="&cfg.getString("loading_phrase"))
    Log("Fetching")
    cfg.fetch(86400)
End Sub

Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Config_onFetchComplete(success As Boolean)
    Log($"Config_onFetchComplete(${success})"$)
    If success Then
        Log("Activate fetched values")
        cfg.activateFetched
        Log("loading_phrase="&cfg.getString("loading_phrase"))
    End If

End Sub

LogCat connected to: 9885e6514556383552
--------- beginning of system** Service (starter) Create **
** Activity (main) Create, isFirst = true **
Hallo world!
Fetching
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Fetch Succeeded
lib:Raising.. config_onfetchcomplete()
Config_onFetchComplete(true)
Activate fetched values
loading_phrase=DonManfred presents


SETUP:
- Use V2.5+ of the Library.
- Follow the Firebaseintegration Tutorial

Replace in the Manifesteditor the line
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)

with

B4X:
CreateResourceFromFile(Macro, FirebaseRemoteConfig.Firebase)

NOTES:
- If you ran into an Error
protobuf-lite Maven artifact not found
then please copy the file com.google.protobuf-protobuf-lite.jar to your additional library folder
 

Attachments

  • FirebaseRemoteConfigV2.01.zip
    7.7 KB · Views: 879
  • RemoteConfigEx.zip
    8.2 KB · Views: 876
  • src.zip
    3.6 KB · Views: 800
  • com.google.protobuf-protobuf-lite.jar
    240.7 KB · Views: 840
  • FirebaseRemoteConfigV2.52.zip
    8.6 KB · Views: 855
Last edited:

ivan.tellez

Active Member
Licensed User
Longtime User
Great Work!

Please consider adding the DependsOn, and also, could you consider renaming your lib to FirebaseRemoteConfig?

In this way you can make developers happier.

Thanks
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @DonManfred! First of all thanks for this wonderful and useful library!
A little donation was sent to show you my appreciation :)

I have tested the library and I can read parameters without problems using your library (Get... methods).
But how to update (write) the existing (firebase remote config) parameters using your library ?
 

DonManfred

Expert
Licensed User
Longtime User
But how to update (write) the existing (firebase remote config) parameters using your library ?
Change the defaults in firebase console... There is no method to update in the lib. Remoteconfig is the way to get the defaults based on your settings in fb console
 

desof

Well-Known Member
Licensed User
Longtime User
How do I add the reference?

B4A version: 6.50
Parsing code. Error
Error parsing program.
Error description: Unknown type: remoteconfig
Are you missing a library reference?
Occurred on line: 28 (Main)
Dim cfg As RemoteConfig
 

desof

Well-Known Member
Licensed User
Longtime User
Hello,

Congratulations on this work is really very useful!
Now I have problems because it always returns me default values not those of Firebase parameters!

Why does this happen ?
 

desof

Well-Known Member
Licensed User
Longtime User
This is the code of your example.
It always gives me the same value for more than I change in Firebase the value of the parameter and save.


B4X:
 Sub Activity_Create (FirstTime As Boolean)
    "No se olvide de cargar el archivo de diseño creado con el diseñador visual. Por ejemplo:
    Activity.LoadLayout ( "Layout1")
'cfg.Defaults
    cfg.Initialize ( "Configuración")   
    cfg.Defaults (CreateMap ( "loading_phrase": "Hola mundo"))
    Log ( "loading_phrase =" & cfg.getString ( "loading_phrase"))
    Log ( "atractivo")
    cfg.fetch (86400)
End Sub

Sub Activity_Resume
End Sub
Activity_Pause sub (UserClosed As Boolean)
End Sub

Sub Config_onFetchComplete (éxito As Boolean)
    Log ($ "Config_onFetchComplete ($ {} éxito)" $)
   
    Si el éxito Entonces
        cfg.activateFetched       
        Log ( "Activar valores inverosímiles")       
        Log ( "loading_phrase =" & cfg.getString ( "loading_phrase"))       
        ToastMessageShow (cfg.getString ( "loading_phrase"), True)       
        Label1.Text = cfg.getString ( "loading_phrase")
       
    Terminara si
   
End Sub [/ CODE]

[CODE] Logcat conectado a: B4A-Bridge: Motorola MotoG3
--------- Inicio del principal
** Actividad (principal) Crear, isFirst ** = false
** Actividad (principal) Reanudar **
** Servicio (service1) Destruye **
** Servicio (service1) Crear **
** Servicio (service1) Iniciar **
Conectado a B4A-Bridge (Wi-Fi)
Instalación de archivos.
** Actividad (principal) Pausa, UserClosed ** = false
PackageAdded: paquete: notificacion.desof
[/CÓDIGO]
 

trueboss323

Active Member
Licensed User
Longtime User
If a user emails me for help asking to change a score or setting for them. Instead of changing a setting for all users, I want to change for that specific user. Would this library be able to do that?
 

johndb

Active Member
Licensed User
Longtime User
If a user emails me for help asking to change a score or setting for them. Instead of changing a setting for all users, I want to change for that specific user. Would this library be able to do that?
No. From what I understand, the Remote Configuration would apply to all user's of the application.
 

Gentry

Member
Licensed User
Longtime User
Can we see an example of enabling DeveloperMode? Quickly running into threshold limits while experimenting on how Remote Config can be used. I suspect a javaobject would need to be constructed to set FirebaseRemoteConfigSettings.Builder.isDeveloperMode() = true, but I have no idea how to craft that for a wrapped library like this.

Thank you for the library, and the guidance.

I know, I know, create a new post for this. But it feels like it makes sense to keep this close to the library.

Gentry
 

ivan.tellez

Active Member
Licensed User
Longtime User
This is weird, I'm updating a proyect, made some changes to the manifest, put the 2.51 version of this lib and I get an error with the sample code:

B4X:
Compiling code.    Error
Error compiling program.
Error description: Property: Defaults is writeonly.
Error occurred on line: 253
cfg.Defaults(CreateMap("Month": 1, "loading_phrase": "Hallo world!"))
Word: defaults

Maybe a problem with the XML?
 
Last edited:
Top