Created
February 7, 2020 12:03
-
-
Save Divya0319/dd5a2a47d92106a6ac1bedd7d7840482 to your computer and use it in GitHub Desktop.
Revisions
-
Divya0319 created this gist
Feb 7, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ class LoginActivity : BaseActivity() { public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_login) ButterKnife.bind(this) checkForAppUpdate() } override fun onResume() { super.onResume() mAppUpdateManager = AppUpdateManagerFactory.create(this) mAppUpdateManager.appUpdateInfo .addOnSuccessListener { appUpdateInfo -> // If the update is downloaded but not installed, // notify the user to complete the update. if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) { popupSnackBarForCompleteStatus() } if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) { // If an in-app update is already running, resume the update. try { mAppUpdateManager.startUpdateFlowForResult( appUpdateInfo, AppUpdateType.IMMEDIATE, this, APP_UPDATE_REQ_CODE ) } catch (e: Exception) { Utils.sendCustomCrashlyticsLog(e, null) } } } } private fun checkForAppUpdate() { // Returns an intent object that you use to check for an update. mAppUpdateManager = AppUpdateManagerFactory.create(this) val appUpdateInfoTask = mAppUpdateManager.appUpdateInfo // Checks that the platform will allow the specified type of update. appUpdateInfoTask.addOnSuccessListener { appUpdateInfo -> if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) { // Request the update. Utils.logMessage("Update", "Available") mAppUpdateManager.startUpdateFlowForResult( appUpdateInfo, AppUpdateType.IMMEDIATE, this, APP_UPDATE_REQ_CODE ) } } } private fun popupSnackBarForCompleteStatus() { val snackBar = Snackbar.make( findViewById(R.id.container), "An update has just been downloaded.", Snackbar.LENGTH_INDEFINITE) snackBar.setAction("RESTART") { mAppUpdateManager.completeUpdate() } snackBar.setActionTextColor(ContextCompat.getColor(this, R.color.blue_button_bg)) snackBar.show() } companion object { private const val APP_UPDATE_REQ_CODE = 345 } }