Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Last active September 26, 2019 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaisukeNagata/974425a333e5592f344490585734cff7 to your computer and use it in GitHub Desktop.
Save DaisukeNagata/974425a333e5592f344490585734cff7 to your computer and use it in GitHub Desktop.
Fire Base ABTest
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings
class MainActivity : AppCompatActivity() {
private lateinit var remoteConfig: FirebaseRemoteConfig
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
remoteConfig = FirebaseRemoteConfig.getInstance()
val configSettings = FirebaseRemoteConfigSettings.Builder()
remoteConfig.setConfigSettingsAsync(
configSettings.setMinimumFetchIntervalInSeconds(3600L)
.build())
remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
remoteConfig.fetchAndActivate()
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
val updated = task.getResult()
print(updated)
}
displayWelcomeMessage()
}
}
private fun displayWelcomeMessage() {
val welcomeMessage = remoteConfig.getString(WELCOME_MESSAGE_KEY)
print(welcomeMessage)
myTextView.text = welcomeMessage
}
companion object {
// Remote Config keys
private const val WELCOME_MESSAGE_KEY = "my_custom_event"
}
}