Updated 11 October 2021
In-App Update (Android)
In this blog, we are going to learn about the In-App Update feature in Android. Well, there are surely some benefits of using the In-App Update feature. You must be wondering why and how?
Well, we always want our customers or users to update their application if there is a new version available. As I live in India where most people turned off their auto update from google play store for several reasons therefore if there is a new version available they will not able to know.
That’s where this library comes into play. Now you can easily prompt the user to update the application if the user allows then you can update the application. With the In-App update feature, the user can also interact with the application. Now the user doesn’t have to explicitly go to google play store to check for any update available for that application.
An In-app update is introduced as a part of the Play Core Library, which actually allows you to prompts the user to update the application when there is any update available on the Google Play Store.
There are two modes to use an In-app update feature.
In Flexible update, the dialog will appear and after the update, the user can interact with the application. This mode is only recommended to use when there is no critical or core change applied to your application.
In Immediate Update, the full-screen UI shows in our application and this is best to use when there is critical core functionality is getting affected and when the immediate update is selected the user can’t interact with the application and after the update, the application gets restarted.
1 |
implementation 'com.google.android.play:core:1.6.4' |
1 |
valupdateManager = AppUpdateManagerFactory.create(mContext) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
private var installStateUpdatedListener: InstallStateUpdatedListener = object : InstallStateUpdatedListener { override fun onStateUpdate(state: InstallState) { if (state.installStatus() == InstallStatus.DOWNLOADED) { //CHECK THIS if AppUpdateType.FLEXIBLE, otherwise you can skip updateSnackBarForComplete() } else if (state.installStatus() == InstallStatus.INSTALLED) { if (updateManager != null) { updateManager.unregisterListener(this) } } else { Log.i("TAG", "InstallStateUpdatedListener: state: " + state.installStatus()) } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
fun checkForAppUpdate() { updateManager = AppUpdateManagerFactory.create(mContext) updateManager.registerListener(installStateUpdatedListener) updateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo -> if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE /*AppUpdateType.IMMEDIATE*/)) { try { updateManager.startUpdateFlowForResult( appUpdateInfo, AppUpdateType.FLEXIBLE /*AppUpdateType.IMMEDIATE*/, mContext, APP_UPDATE_REQUEST_CODE) } catch (e: SendIntentException) { e.printStackTrace() } } else if (appUpdateInfo.installStatus() ==InstallStatus.DOWNLOADED) { //CHECK THIS if AppUpdateType.FLEXIBLE, otherwise you can skip updateSnackBarForComplete() } else { Log.e("TAG", "checkForAppUpdateAvailability: something else") } } } |
1 |
updateManager.registerListener(installStateUpdatedListener) |
1 |
updateManager.unregisterListener(listener) |
1 2 3 4 5 6 7 8 |
private fun updateSnackBarForComplete() { val snackbar = Snackbar.make(mContext.findViewById(R.id.main_container), "New Version is downloaded.", Snackbar.LENGTH_INDEFINITE) snackbar.setAction("RESTART") { updateManager.completeUpdate() } snackbar.setActionTextColor(ContextCompat.getColor(mContext, R.color.colorAccent)) snackbar.show() } |
1 2 3 4 5 6 7 8 |
if (requestCode == APP_UPDATE_REQUEST_CODE) { if (resultCode != Activity.RESULT_OK) { Toast.makeText(mContext, "UPDATE FAILED.", Toast.LENGTH_SHORT) .show() } } |
You have to Generate the signed APK or bundle and then go to App-Internal-Sharing in the Play Console and upload the build and after that, you can quickly share an app bundle or APK with your internal team and testers to test the build.
Or
On your test device, make sure you’ve already installed a version of the app using an internal app sharing URL and the device supports in-app updates then it uses a version code that’s lower than the updated version of your app.
. . . . . . . . .
That’s it from my side for today, thanks for reading it until now. If you want to read more about, check out the official developer documentation below:
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.