Skip to content

Commit

Permalink
Show update window only once
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasnlm committed Apr 6, 2021
1 parent a429db5 commit 8edc872
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.UpdateAvailability

class InAppUpdateManager : IInAppUpdateManager {
private var keepRequesting = true

override fun checkUpdate(activity: Activity) {
val appUpdateManager = AppUpdateManagerFactory.create(activity.applicationContext)
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && !activity.isFinishing) {
appUpdateManager.startUpdateFlow(
appUpdateInfo,
activity,
AppUpdateOptions.defaultOptions(AppUpdateType.FLEXIBLE)
)
if (keepRequesting) {
keepRequesting = false
val appUpdateManager = AppUpdateManagerFactory.create(activity.applicationContext)
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE &&
!activity.isFinishing
) {
appUpdateManager.startUpdateFlow(
appUpdateInfo,
activity,
AppUpdateOptions.defaultOptions(AppUpdateType.FLEXIBLE)
)
}
}
}
}
Expand Down

0 comments on commit 8edc872

Please sign in to comment.