Last active
May 27, 2019 17:46
-
-
Save dhruvtaneja/6978134bd6835fa73bd5788980232299 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity(), InstallStateUpdatedListener { | |
override fun onStateUpdate(installState: InstallState) { | |
if (installState.installStatus() == InstallStatus.DOWNLOADED) { | |
notifyUser() | |
} | |
} | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
appUpdateManager = AppUpdateManagerFactory.create(this) | |
appUpdateManager.registerListener(this) | |
appUpdateManager.appUpdateInfo.addOnSuccessListener { | |
if (it.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && | |
it.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) { // check for the type of update flow you want | |
requestUpdate() | |
} | |
} | |
override fun onDestroy() { | |
super.onDestroy() | |
appUpdateManager.unregisterListener(this) | |
} | |
private fun notifyUser() { | |
Snackbar | |
.make(appVersionTextView, R.string.restart_to_update, Snackbar.LENGTH_INDEFINITE) | |
.setAction(R.string.action_restart) { | |
appUpdateManager.completeUpdate() | |
appUpdateManager.unregisterListener(this) | |
} | |
.show() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment