It is recommended to use when you need to prepare simply without setting up the firebase console, or when you need to avoid the remote configuration limitation specification of Firebase.
However, firebase is more efficient if you need a complex configuration, use firebase's detailed features, or do not have a server that is guaranteed to run 24 hours a day, 365 days a year.
Add the JitPack repository in your build.gradle (top level module):
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
And add next dependencies in the build.gradle of the module:
android {
/// ...
compileOptions {
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.github.seoft:AndroidRemoteConfig:0.9.5'
}
{
"version": null,
"message": "Set here normal message",
"run": true,
"etc": "Set here etc message if you need"
}
type : Int?
example : null or 1 or 20
detail : If the gradle version code is lower than the following value, the onLowVersion function is called. If null, onLowVersion function is not called.
code example :
override fun onLowVersion(message: String?, etc: String?) {
Log.d(TAG, "onLowVersion $message $etc")
// message is "Get a new version from the Play Store"
Toast.makeText(baseContext, message, Toast.LENGTH_LONG).show()
finish()
}
type : String?
example : null or "Get a new version from the Play Store" or "The server is under maintenance until 11:00. Please excute the app after 11 o'clock"
detail : If it is not null, it is delivered as a message of onRun, onBlock, onLowVersion functions.
type : Boolean
example : true or false
detail : Value of whether the app is running.
type : String?
example : null or "etc value"
detail : Define additional required values, it is delivered as a etc of onRun, onBlock, onLowVersion functions.
val processRemoteConfig1 =
ProcessRemoteConfig.Builder("https://raw.githubusercontent.com/seoft/AndroidRemoteConfig/dev/json_for_test/normal_run_with_etc_message.json")
.isDebug(true)
.requestTimeoutSecond(30)
.versionCode(BuildConfig.VERSION_CODE)
.build()
address to request remote config value.
whether the AndroidRemoteConfig module's logging.
request timeout second
The gradle version code of the current app to be compared with RemoteConfig
//https://raw.githubusercontent.com/seoft/AndroidRemoteConfig/dev/json_for_test/normal_run_with_etc_message.json
processRemoteConfig1.requestRemoteConfig(object : OnRemoteConfigListener {
override fun onRun(message: String?, etc: String?) {
Log.d(TAG, "onRun $message $etc")
Toast.makeText(baseContext, "onRun $message $etc", Toast.LENGTH_LONG).show()
startActivity(Intent(baseContext, MainActivity::class.java))
finish()
}
override fun onResponseFail(throwable: Throwable) {
// try when failed
}
})
}
//https://raw.githubusercontent.com/seoft/AndroidRemoteConfig/dev/json_for_test/block_launch.json
processRemoteConfig2.requestRemoteConfig(object : OnRemoteConfigListener {
override fun onRun(message: String?, etc: String?) {
Log.d(TAG, "onRun $message $etc")
startActivity(Intent(baseContext, MainActivity::class.java))
finish()
}
override fun onBlock(message: String?, etc: String?) {
Log.d(TAG, "onBlock $message $etc")
Toast.makeText(baseContext, message, Toast.LENGTH_LONG).show()
finish()
}
})
//https://raw.githubusercontent.com/seoft/AndroidRemoteConfig/dev/json_for_test/when_version_is_low.json
processRemoteConfig3.requestRemoteConfig(object : OnRemoteConfigListener {
override fun onRun(message: String?, etc: String?) {
Log.d(TAG, "onRun $message $etc")
startActivity(Intent(baseContext, MainActivity::class.java))
finish()
}
override fun onBlock(message: String?, etc: String?) {
Log.d(TAG, "onBlock $message $etc")
Toast.makeText(baseContext, message, Toast.LENGTH_LONG).show()
finish()
}
override fun onLowVersion(message: String?, etc: String?) {
Log.d(TAG, "onLowVersion $message $etc")
// message is "Get a new version from the Play Store"
Toast.makeText(baseContext, message, Toast.LENGTH_LONG).show()
finish()
}
})
//https://raw.githubusercontent.com/seoft/AndroidRemoteConfig/dev/json_for_test/when_version_is_low.json
processRemoteConfig4.createRxSingleRemoteConfig()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
it.run {
when (this) {
is RemoteConfigResult.Run -> {
Log.d(TAG, "onRun $message $etc")
startActivity(Intent(baseContext, MainActivity::class.java))
finish()
}
is RemoteConfigResult.LowVersion -> {
Log.d(TAG, "onLowVersion $message $etc")
// message is "Get a new version from the Play Store"
Toast.makeText(baseContext, message, Toast.LENGTH_LONG).show()
finish()
}
is RemoteConfigResult.Block -> {
Log.d(TAG, "onBlock $message $etc")
Toast.makeText(baseContext, message, Toast.LENGTH_LONG).show()
finish()
}
is RemoteConfigResult.Fail -> {
// try when failed
this.throwable.printStackTrace()
}
}
}
}, {
it.printStackTrace()
})
})
//https://raw.githubusercontent.com/seoft/AndroidRemoteConfig/dev/json_for_test/when_version_is_low.json
// Set up the scope you need
GlobalScope.launch {
processRemoteConfig5.createCoroutineRemoteConfig().run {
when (this) {
is RemoteConfigResult.Run -> {
Log.d(TAG, "onRun $message $etc")
startActivity(Intent(baseContext, MainActivity::class.java))
finish()
}
is RemoteConfigResult.LowVersion -> {
Log.d(TAG, "onLowVersion $message $etc")
// message is "Get a new version from the Play Store"
Toast.makeText(baseContext, message, Toast.LENGTH_LONG).show()
finish()
}
is RemoteConfigResult.Block -> {
Log.d(TAG, "onBlock $message $etc")
Toast.makeText(baseContext, message, Toast.LENGTH_LONG).show()
finish()
}
is RemoteConfigResult.Fail -> {
// try when failed
this.throwable.printStackTrace()
}
}
}
}
Change the json value of the url that sends the request ProcessRemoteConfig when the server dies unexpectedly and you need to notify the notification, or when you need to forcibly update users of the previous version.