Last active
August 10, 2019 19:22
-
-
Save motorro/3673e78cd05cf14b7a4ed65447e2ce90 to your computer and use it in GitHub Desktop.
Activity with AppUpdateWrapper
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
/** | |
* 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() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment