Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Basic activity that runs flexible update
- */
- class FlexibleUpdateActivity : AppCompatActivity(), AppUpdateView {
- /**
- * Update flow
- */
- private lateinit var updateWrapper: AppUpdateWrapper
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- // Creates flexible update flow that (if cancelled) will ask again tomorrow
- updateWrapper = startFlexibleUpdate(
- AppUpdateManagerFactory.create(this.applicationContext),
- this,
- UpdateFlowBreaker.forOneDay(getSharedPreferences("uiState", Context.MODE_PRIVATE))
- )
- }
- // Passes an activity result to wrapper to check for play-core interaction
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- super.onActivityResult(requestCode, resultCode, data)
- if (updateWrapper.checkActivityResult(requestCode, resultCode)) {
- // Result handled and processed
- return
- }
- // Process your request codes
- }
- /********************************/
- /* AppUpdateView implementation */
- /********************************/
- // AppUpdateManager needs your activity to start dialogs
- override val activity: Activity get() = this
- // Update is downloaded and ready to install
- override fun updateReady() {
- // Display confirmation dialog of your choice and complete update...
- updateWrapper.userConfirmedUpdate()
- // ...or cancel it
- updateWrapper.userCanceledUpdate()
- }
- // Update check critical error (effective for IMMEDIATE flow)
- override fun updateFailed(e: Throwable) {
- Toast.makeText(this, "Update failed", Toast.LENGTH_SHORT).show()
- finish()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement