Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. /**
  2. * Basic activity that runs flexible update
  3. */
  4. class FlexibleUpdateActivity : AppCompatActivity(), AppUpdateView {
  5. /**
  6. * Update flow
  7. */
  8. private lateinit var updateWrapper: AppUpdateWrapper
  9.  
  10. override fun onCreate(savedInstanceState: Bundle?) {
  11. super.onCreate(savedInstanceState)
  12. // Creates flexible update flow that (if cancelled) will ask again tomorrow
  13. updateWrapper = startFlexibleUpdate(
  14. AppUpdateManagerFactory.create(this.applicationContext),
  15. this,
  16. UpdateFlowBreaker.forOneDay(getSharedPreferences("uiState", Context.MODE_PRIVATE))
  17. )
  18. }
  19.  
  20. // Passes an activity result to wrapper to check for play-core interaction
  21. override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
  22. super.onActivityResult(requestCode, resultCode, data)
  23. if (updateWrapper.checkActivityResult(requestCode, resultCode)) {
  24. // Result handled and processed
  25. return
  26. }
  27. // Process your request codes
  28. }
  29.  
  30. /********************************/
  31. /* AppUpdateView implementation */
  32. /********************************/
  33.  
  34. // AppUpdateManager needs your activity to start dialogs
  35. override val activity: Activity get() = this
  36.  
  37. // Update is downloaded and ready to install
  38. override fun updateReady() {
  39. // Display confirmation dialog of your choice and complete update...
  40. updateWrapper.userConfirmedUpdate()
  41. // ...or cancel it
  42. updateWrapper.userCanceledUpdate()
  43. }
  44.  
  45. // Update check critical error (effective for IMMEDIATE flow)
  46. override fun updateFailed(e: Throwable) {
  47. Toast.makeText(this, "Update failed", Toast.LENGTH_SHORT).show()
  48. finish()
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement