はじめに
今回は、AndroidでRemoteConfigを受け取る部分を紹介していこうと思います
本文
MainActivityのonCreate内で下記の処理を追加します。
remoteConfig
からgetStringでparameter
のkey
を指定することでほしい値をJsonStringで取得することができます
MainActivty
val remoteConfig: FirebaseRemoteConfig = Firebase.remoteConfig
remoteConfig.fetchAndActivate()
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
RemoteConfigParameter.values().map {
// 行いたい処理を記述
}
}
}
remoteConfig.addOnConfigUpdateListener(object : ConfigUpdateListener {
override fun onUpdate(configUpdate: ConfigUpdate) {
RemoteConfigParameter.values().map {
if (configUpdate.updatedKeys.contains(it.key)) {
// 行いたい処理を記述
}
}
}
override fun onError(error: FirebaseRemoteConfigException) {}
})
最後に
今回はAndroideでのRemoteConfigを使った処理を紹介しました
備忘録程度ですがどなたかのお役に立てれば幸いです