Skip to content

Instantly share code, notes, and snippets.

@gokmenbayram
Last active December 13, 2020 12:07
Show Gist options
  • Save gokmenbayram/89f8f12ee4c917277d2eb33ea7cb5d60 to your computer and use it in GitHub Desktop.
Save gokmenbayram/89f8f12ee4c917277d2eb33ea7cb5d60 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
private val apiClient by lazy { FirebaseClient() }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
apiClient.getAppVersionFromApi { isSuccess, response, message ->
if (isSuccess) {
var newVersion = response?.documents?.first()?.fields?.app_version?.version
var appVersion = appVersion(this)
if (appVersion != newVersion)
showAlert(this)
}
}
}
private fun appVersion(context: Context): String {
var manager = context.packageManager
var info = manager.getPackageInfo(context.packageName, 0)
return info.versionName
}
private fun showAlert(context: AppCompatActivity) {
val alert = AlertView("Force Update", "Uygulamanızın yeni versiyonu mevcuttur. Güncellemek için tıklayın.", AlertStyle.DIALOG)
alert.addAction(AlertAction("Güncelle", AlertActionStyle.POSITIVE, {
// Play Store'a yonlendir.
}))
alert.addAction(AlertAction("Vazgeç", AlertActionStyle.NEGATIVE, {
}))
alert.show(context)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment