Fix in-app update

This commit is contained in:
世界 2023-11-07 22:25:47 +08:00
parent 56a27728b9
commit d10c6ebd7e
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -194,6 +194,7 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
}
UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS -> {
Log.d(TAG, "checkUpdate: in progress, status: ${appUpdateInfo.installStatus()}")
when (appUpdateInfo.installStatus()) {
InstallStatus.DOWNLOADED -> {
appUpdateManager.completeUpdate()
@ -202,6 +203,7 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
}
UpdateAvailability.UPDATE_AVAILABLE -> {
Log.d(TAG, "checkUpdate: available")
if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
appUpdateManager.startUpdateFlow(
appUpdateInfo,
@ -218,12 +220,18 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
}
UpdateAvailability.UNKNOWN -> {
Log.d(TAG, "checkUpdate: unknown")
}
}
}
appUpdateInfoTask.addOnFailureListener {
Log.e(TAG, "checkUpdate: ", it)
}
appUpdateManager.registerListener { state ->
if (state.installStatus() == InstallStatus.DOWNLOADED) {
appUpdateManager.completeUpdate()
}
}
}
@SuppressLint("NewApi")