Can I declare an array to Firebase Remote config?

Munir Hoque picture Munir Hoque · Feb 13, 2017 · Viewed 10.6k times · Source

I am a novice to Android and Firebase. Is it possible to declare an array inside the the Parameter key of Firebase Remote Config? enter image description here

I want to provide some promotions to some specific models/mobile devices. So if I could declare an array of models(i,e, Samsung J5, Xiaomi Note2 etc) I could easily enable promotions on those models. Please help me.

Answer

android_dev picture android_dev · Jan 20, 2019

The Remote Config has recently added the option to save a key-value list by saving it to a JSON format.

enter image description here

Sample usage:

1.Json stored in Remote Configs:

 [
      {
        "lesson": "1",
        "versionCode": 2
      },
      {
        "lesson": "2",
        "versionCode": 4
      },
      {
        "lesson": "3",
        "versionCode": 1
      }
 ]

2.Kotlin model

data class Lesson(val lesson: Int, val versionCode: Int)

3.Retrieve json

String object = FirebaseRemoteConfig.getInstance().getString("test_json");
Gson gson = new GsonBuilder().create();
List<Lesson> lessons = gson.fromJson(object, new TypeToken<List<Lesson>>(){}.getType());