我想在我的应用程序中集成灵活的更新。这是我的代码:
fun checkForUpdates(){
val appUpdateManager = AppUpdateManagerFactory.create(this)
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
val listener = InstallStateUpdatedListener {
if (it.installStatus() == InstallStatus.DOWNLOADED){
val snackBar = Snackbar.make(parentLayout, "An update has just been downloaded.", Snackbar.LENGTH_INDEFINITE)
snackBar.duration = 10000
snackBar.view.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimaryDark))
snackBar.setActionTextColor(ContextCompat.getColor(this, R.color.white))
snackBar.setAction("RESTART") {
appUpdateManager.completeUpdate()
}
snackBar.show()
}
}
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo->
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)){
appUpdateManager.registerListener(listener)
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.IMMEDIATE,
this,
UPDATE_REQUEST_CODE)
}
}
}
我在测试它时遇到问题。我尝试减少我的构建版本号,但它似乎不起作用。