- Implement In-app Update In Android
- Make sure every user of your app is on the new version.
- What is In-App Update:
- Flexible Update:
- Benefits:
- How to work with Android’s in-app update API?
- 7 Answers 7
- In-app updates
- Update flows
- Flexible updates
- Immediate updates
- Support in-app updates in your app
- Programmatically check Play Store for app updates
- 19 Answers 19
- How can I test In-app updates in Android?
- 11 Answers 11
- Testing using Internal App Sharing
- Testing using Alpha (closed track)
Implement In-app Update In Android
Make sure every user of your app is on the new version.
Apr 6, 2020 · 8 min read
In this article, we will learn about the In-app update feature in Android what is all about In-app update, what are the benefits of using the In-app update in your android application. Recently I’ve been working on a product in which I need to Implement an In-app update Why we need to Implement this?.
As a Developer we always want our users to have the updated version of their application but there are a lot of people who actually turned off their auto update from google play store and he/she doesn’t know about any update available or not.
To overcome the problem Google Introduced this feature called In-app update from this feature you can easily prompt the user to update the application and with the user permission you can update the application also while updating the app user can be able to interact with the application. Now the user doesn’t need to go to google play store to check there is any update available or not.
What is In-App Update:
An In-app update was 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 of an In-app update.
- Flexible Update
- Immediate Update
Flexible Update:
In Flexible update, the dialog will appear and after the update, the user can interact with the application.
This mode is recommended to use when there is no major change In your application like some features that don’t affect the core functionality of your application.
The update of the application is downloading in the background in the flexible update and after the completion of the downloading, the user will see the dialog in which the user needs to restart the application. The dialog will not automatically show, we need to check and show to the user and we will learn how later.
Benefits:
The major benefit of the flexible update is the user can interact with the application.
Источник
How to work with Android’s in-app update API?
I recently came across a new kind of app update flow which has provided by Google Play API. I liked this seamless flow to update an Android application. I observed the below-mentioned steps in the Hotstar app.
- A card popped up from the bottom showing update is available
- When I clicked on «Update Hotstar» button, one dialog popped up (seems like it is provided by Google Play)
- Downloading was started in the background while the app was running
- After completion of the download, one SnackBar popped up showing app ready to install
- App restarted after the installation
How can I achieve this? There must be a way to communicate with Google Play. I went through many blogs. But, didn’t find any solution. This could be an awesome feature for a developer if the auto app update is disabled by the user.
7 Answers 7
Step 1: Add dependency (build.gradle (app)):
Step 2: Check for update availability and start if it’s available
In onStart() method:
Step 3: Listen to update state
Step 4: Get a callback for update status
Step 5: Flexible update
Step 6: Don’t forget to unregister listener (in onStop method)
Note: Add this listener in any one activity in your app preferably in MainActivity (Home page)
For testing, you can use FakeAppUpdateManager
Constraint: In-app update works only with devices running Android 5.0 (API level 21) or higher
Update: Handling both IMMEDIATE and FLEXIBLE updates in a single activity; Kotlin way.
Trying to implement this, the official Google Documentation quoted in the accepted answer is syntactically incorrect. It took some research, but I finally found the correct syntax:
Then, code a similar bit of code in the onResume() override in case an install got hung up along the way:
Step 1: In the build.gradle file add the below library (please check and update latest play code plugin version)
Step 2: Declare the following variables in class (Ex MainActivity.java)
Step 3: In onCreate() method add the below code (initializing variables)
Step 4: In onDestroy() method of activity just unregister the listener
Step 5: In onResume() we need to listen to both Flexible and Immediate updates by the below code.
Step 6: In onActivityResult() we need to handle user click actions(only for flexible update)
Step 7: Create a method to check update available or not and start the update (Immediate update)
Step 8: Finely create a snack dialog or any alert to show the user that flexible update is downloaded and ready to update(need used action to start update — only for flexible update)
Step 9: Now call the method with the in-app update type(Flexible or Immediate) wherever you want to start to check updates.
Points to Remember:
The flexible update will download first then it will notify the user that download completed then the user has to start the update(options given above step 8).
There is an option in google play console to test in-app sharing, just we can upload normal apk(no need signed apk)to test. https://support.google.com/googleplay/android-developer/answer/9303479?hl=en
Need to enable in-app sharing option in your test device play store app. How to Enable Internal App Sharing for Android?
Still, any issue in the play store, just clear cache and clear data then restart the device once and try.
My guess is that it is controlled by the app itself, rather than Google Play. I’ve developed apps that make an API call on startup to read the ‘latest’ version number and whether that version is a ‘mandatory’ update or not, and compares it to the running app version. If a new version is available, the user is presented with a dialog like the one you displayed (though their’s is much nicer) alerting the user that an update is available. If the update is ‘mandatory’, then the message tells them that they must update the app before continuing. If they click Update, then they are taken to the App Store page where they initiate the download of the update as usual and the app exits. If they click Close, the app just exits. If the update is not mandatory, they are asked if they would like to update now, or continue. If they click Update, then they are taken to the App Store page where they initiate the download of the update as usual and the app exits. If they click Continue, then they are just taken into the existing version of the app.
I’m not sure how they managed the background download then kicked off the app update before exiting the app. That would be very nice, but our method above was also very easy and gives a lot of capability to the developer.
Источник
In-app updates
When your users keep your app up to date on their devices, they can try new features, as well as benefit from performance improvements and bug fixes. Although some users enable background updates when their device is connected to an unmetered connection, other users might need to be reminded to install updates. In-app updates is a Play Core library feature that prompts active users to update your app.
The in-app updates feature is supported on devices running Android 5.0 (API level 21) or higher, and requires your app to use Play Core library version 1.5.0 or higher. Additionally, in-app updates are only supported for Android mobile devices, Android tablets, and Chrome OS devices.
Update flows
Your app can use the Play Core library to support the following UX flows for in-app updates:
Flexible updates
Flexible updates provide background download and installation with graceful state monitoring. This UX flow is appropriate when it’s acceptable for the user to use the app while downloading the update. For example, you might want to encourage users to try a new feature that’s not critical to the core functionality of your app.
Figure 1. An example of a flexible update flow.
Immediate updates
Immediate updates are fullscreen UX flows that require the user to update and restart the app in order to continue using it. This UX flow is best for cases where an update is critical to the core functionality of your app. After a user accepts an immediate update, Google Play handles the update installation and app restart.
Figure 2. An example of an immediate update flow.
Support in-app updates in your app
Learn how to support in-app updates in your app, depending on your development environment:
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Источник
Programmatically check Play Store for app updates
I have put my app on the Google Play Store. It has been installed by lots of my company’s customers. I understand the mechanism of how the app is intended to upgrade.
The users should check the auto-update check box in the Playstore app for each app they want to auto-update. However some users have unchecked it or not checked it in the first place.
The app i have written is for the care industry and is used by carers to deliver homecare. Some of our customers my have 1200 carers. They would have to call all the carers into the office to update the phones individually. This is obviously unacceptable.
Is there a way to programmatically check if there is an updated version of my app on the Play Store?
Could i have code that runs every time the user starts the app that checks the Play Store? If there is an updated version then the user could be directed to the Playstore. This will mean it is not essential to have the auto-update checked.
19 Answers 19
Update 17 October 2019
Update 24 april 2019:
Android announced a feature which will probably fix this problem. Using the in-app Updates API: https://android-developers.googleblog.com/2018/11/unfolding-right-now-at-androiddevsummit.html
Original:
As far a I know, there is no official Google API which supports this.
You should consider to get a version number from an API.
Instead of connecting to external APIs or webpages (like Google Play Store). There is a risk that something may change in the API or the webpage, so you should consider to check if the version code of the current app is below the version number you get from your own API.
Just remember if you update your app, you need to change the version in your own API with the app version number.
I would recommend that you make a file in your own website or API, with the version number. (Eventually make a cronjob and make the version update automatic, and send a notification when something goes wrong)
You have to get this value from your Google Play Store page (is changed in the meantime, not working anymore):
Check in your app if the version used on the mobile is below the version nummer showed on your own API.
Show indication that she/he needs to update with a notification, ideally.
Источник
How can I test In-app updates in Android?
Recently, Google introduced ‘in-app updates’ in Google I/O 2019.
So I am trying to use it.
But the result.updateAvailability() is always UpdateAvailability.UPDATE_NOT_AVAILABLE .
To do this, I made a signed release apk with previous version code. But it doesn’t work.
According to the demo on the Developer Keynote (16:40
He is doing it with the emulator. It looks like debug mode.
How can I do this same thing?
11 Answers 11
Testing using Internal App Sharing
The right way to test in-app update is to use Internal App Sharing (not to be confused with Internal Testing Track).
- First setup your Internal App Sharing with the help of these instructions. Unlike Internal Testing Track, Internal App Sharing makes the app available immediately. So there is no waiting time.
- Opt-in to app signing by Google Play. This will allow google play to sign the apk generated for the device from the app bundle you provide. Details here.
- Build your app bundle. Through command line, it is simply ./gradlew bundleRelease or ./gradlew bundle .
- Go to https://play.google.com/apps/publish/internalappsharing/ and upload the generated aab file which is under app/build/outputs/bundle/ / . Give a decent name that includes version code.
- This will provide a link to copy. Use it to install this bundle to your device.
- Bump the version code in your app build.gradle and build another bundle. Note: Version code is integer, that’s what is to be incremented. Version name is different and it doesn’t matter for this.
- Similarly upload this new bundle to Internal App Sharing. Name it with the version code.
- This will provide another link. Open the link and this opens google play and you should see «Update» option. Don’t click on Update!
- Open your app and now you should see in-app update prompt.
If you don’t see the prompt and if you had followed these steps exactly, most likely, there is an issue with your code. Add some logging to see what is happening in your code.
In our testing, the following did NOT help to test in-app updates (which were suggested elsewhere):
- Re-uploading the same bundle/apk without bumping up the version code
- Decreasing version code to be lower than the published version
Testing using Alpha (closed track)
Once testing through internal app sharing is successful, I still found some trouble testing in-app update through published versions. After some trials, I was able to successfully test through Alpha track. I’m adding the steps here (I’m assuming you’re familiar with Google Play console’s Alpha closed track and adding yourself as alpha tester list):
- Install current version of the app through Google Play. This can be from production track or alpha or beta track. This version should already have in-app update feature implemented as this is the version that is expected to show in-app update prompt.
- Ensure that Automatic Update is disabled just for your app. You can do this through menu item of your app’s store listing on Google Play app. We disable automatic update because, we really want to update the app through in-app update instead of Google Play updating the app when your device is charging.
- Publish a new version (with version code incremented, changing version name won’t matter) to Alpha track.
- Nowadays, it takes a while before the published version shows up in Google Play. You may have to wait for several hours.
- Once it shows up in Google Play store, you may eagerly try opening your app. You’ll be lucky if in-app update prompt shows up. Most likely it won’t. In-app update may not show up even if you kept on waiting for several more hours and kept restarting your app. By following the remaining steps I didn’t have to wait.
- Close your app completely.
- Close Google Play app completely.
- Clear Google Play app cache. I found that storage need not to be cleared, just the cache.
- Open Google Play and go to My Apps & Games from navigation pane.
- Now Google Play will search for the updates. Your app update should show up. Do NOT update here, of course.
- Open your app. In-app update prompt should appear. If not, test your in-app update with internal app sharing (steps in previous section) and ensure there is no problem with your implementation.
I guess similar process should work for Beta (open track) and production tracks as well.
Even after the update is available through Google Play, for the end-users to see in-app update, I think it may take quite some time (days!). Google Play has its own confusing ways. Good luck.
Источник