0
0

AndroidでのRemoteConfig実装方法

Posted at

はじめに

今回は、AndroidでRemoteConfigを受け取る部分を紹介していこうと思います

本文

MainActivityのonCreate内で下記の処理を追加します。
remoteConfigからgetStringでparameterkeyを指定することでほしい値を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を使った処理を紹介しました
備忘録程度ですがどなたかのお役に立てれば幸いです

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0