- Saved searches
- Use saved searches to filter your results more quickly
- License
- SanojPunchihewa/InAppUpdater
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Android — In-App Updates API Flexible and Immediate Show Update Available Dialog Inside App
- Requirements
- Flexible
- Immediate
- Implementing FLEXIBLE mode
- Implementing IMMEDIATE mode
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Android Library to easily implement in-app updates. Support with a ⭐ Contributions are welcome! 🙌
License
SanojPunchihewa/InAppUpdater
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
…x.appcompat-appcompat-1.2.0 Bump appcompat from 1.1.0 to 1.2.0
Git stats
Files
Failed to load latest commit information.
README.md
Android Library to easily implement in-app updates
Step 1: Add it in your root build.gradle
allprojects < repositories < maven < url "https://jitpack.io" > > >
Step 2: Add the dependency
dependencies < implementation 'com.github.SanojPunchihewa:InAppUpdater:1.0.5' >
Step 3: Initialize the UpdateManager
Declare the UpdateManager in your Activity
// Declare the UpdateManager UpdateManager mUpdateManager;
Initialize the UpdateManager in your onCreate method of the Activity
// Initialize the Update Manager with the Activity and the Update Mode mUpdateManager = UpdateManager.Builder(this).mode(UpdateManagerConstant.FLEXIBLE); mUpdateManager.start();
Update Mode
- Flexible( UpdateManagerConstant.FLEXIBLE ) (default) — User can use the app during update download, installation and restart needs to be triggered by user
- Immediate( UpdateManagerConstant.IMMEDIATE ) — User will be blocked until download and installation is finished, restart is triggered automatically
Additionally you can get the Available Version Code of the update and the Number of days passed since the user was notified of an update through the Google Play. You can find these codes in the demo app
mUpdateManager.addUpdateInfoListener(new UpdateInfoListener() < @Override public void onReceiveVersionCode(final int code) < // You can get the available version code of the apk in Google Play // Do something here > @Override public void onReceiveStalenessDays(final int days) < // Number of days passed since the user was notified of an update through the Google Play // If the user hasn't notified this will return -1 as days // You can decide the type of update you want to call > >);
Monitoring the flexible update download progres
You can monitor the download progress of a Flexible Update using this callback. Note: This is only available for Flexible update mode. You can find more from the official doc
// Callback from Flexible Update Progress mUpdateManager.addFlexibleUpdateDownloadListener(new FlexibleUpdateDownloadListener() < @Override public void onDownloadProgress(final long bytesDownloaded, final long totalBytes) < // Show a progress bar or anything you want > >);
- In-app updates works only with devices running Android 5.0 (API level 21) or higher
- In-app updates are available only to user accounts that own the app. So, make sure the account you’re using has downloaded your app from Google Play at least once before using the account to test in-app updates.
- Make sure that the app that you are testing in-app updates with has the same application ID and is signed with the same signing key as the one available from Google Play.
- Because Google Play can only update an app to a higher version code, make sure the app you are testing as a lower version code than the update version code.
You can find more information at Frequently Asked Questions
Any contributions are welcome!
MIT License Copyright (c) 2019 Sanoj Punchihewa Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
About
Android Library to easily implement in-app updates. Support with a ⭐ Contributions are welcome! 🙌
Android — In-App Updates API Flexible and Immediate Show Update Available Dialog Inside App
As mobile developers we usually want our users to have the most up-to-date version application so that they can try new features, improve performance, and bug fixes if there exist.
Traditionally, users have to go to the Playstore app and update the app manually or automatically when connected to wifi. Today we can learn how to create an app with an update dialog inside our app and update without going to Playstore by using in-app update.
In-App updates feature is supported on devices running Android 5.0 or higher version. we required dependency Play Core Library version 1.5.0 or higher. Moreover, this feature only supported Android mobile devices, Android tablets, and Chrome OS devices.
In-app update has 2 modes of an In-app update Flexible and Immediate.
Requirements
Flexible
- Mid-dialog pop up shows overlay on the screen
- Users still continue using the app while download update in the background
Immediate
- Full-screen dialog overlay
- Users have to wait for download update completely before we can use the app.
Implementing FLEXIBLE mode
Step 1: Create a new project in Android Studio (File -> New -> Project -> Select Empty Activty -> Name project AppUpdateTest -> Finish)
Step 2: Add the Google Play Core Dependency to android build.gradle file (Module: app). Note: My latest play core version (video) was 1.7.3 but you can use the latest stable release you want from Play Core Library.
After we add the library above we have to click on sync link on the top right corner to pull and download the dependency.
Step 3: Open MainActivity.java then we have to instance of the AppManager to get the in-app update info, which is in OnCreate method like the below snippet
Step 4: We will get update information from Playstore and check the update is available or not, before making a request for the update.
() < @Override public void onSuccess(AppUpdateInfo result) < if(result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && result.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) < try < mAppUpdateManager.startUpdateFlowForResult(result,AppUpdateType.FLEXIBLE, MainActivity.this ,RC_APP_UPDATE); >catch (IntentSender.SendIntentException e) < e.printStackTrace(); >> > >);
mAppUpdateManager.startUpdateFlowForResult(A,B,C,D); for making the request to Playstore to check for updates.
- A (AppUpdateInfo) is the result update info.
- B (UpdateAvailability) is the enum value type that refers to FLEXIBLE and IMMEDIATE.
- C (Activity) is the current context activity to pass.
- D (Integer) is a random integer number to identify when we use in onActivityResult() method in the next step.
Step 5: After we request and check updates available, it will pop up the dialog. Any way we can choose an action to perform to do next. Example users don’t want to update and clicked cancel, we can track those actions by overriding a method onActivityResult() to check as below
super.onActivityResult(requestCode, resultCode, data); >
The snippet above is to check when the user clicked cancel or x button.
Step 6: We start monitoring the update in the case below we track when the update is completed download.
showCompletedUpdate(); we will create the method below to handle the message and install the update.
mAppUpdateManager.completeUpdate(); use for install the downloaded update.
Step 7: Remember we have defined a function in Step 6 and we have to activate that function, so let’s register the listener in onCreate() method as below.
Step 8: We need to unregister the listener, to avoid the memory leak. like the below code:
Yes, now you are completely creating In-App Update with Flexible mode.
Implementing IMMEDIATE mode
Please follow Step 1,Step 2,Step 3
Step 4: We will get update information from Playstore and check the update is available or not, before making a request for the update. the code below is almost the same we changed the update type FLEXIBLE to IMMEDIATE.
() < @Override public void onSuccess(AppUpdateInfo result) < if(result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && result.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) < try < mAppUpdateManager.startUpdateFlowForResult(result,AppUpdateType.IMMEDIATE, MainActivity.this ,RC_APP_UPDATE); >catch (IntentSender.SendIntentException e) < e.printStackTrace(); >> > >);
Step 5: Please follow Step 5 in Flexible mode
After all, the IMMEDIATE mode does not require registered listener. This mode will automatically install the update after downloaded completely so we no need to call mAppUpdateManager.completeUpdate(); to install manually.
If the user downloading updates in large file size, they might exit the app. To activate when they back to the app we have to override method onResume()
() < @Override public void onSuccess(AppUpdateInfo result) < if(result.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) < try < mAppUpdateManager.startUpdateFlowForResult(result,AppUpdateType.IMMEDIATE, MainActivity.this ,RC_APP_UPDATE); >catch (IntentSender.SendIntentException e) < e.printStackTrace(); >> > >); >
We are checking if the downloading is progressing then we start to continue download the update file.
Alright, follow the above steps you will successfully implement In-app update in FLEXIBLE and IMMEDIATE mode. The video below will completely guide both FLEXIBLE and IMMEDIATE mode including tricky technique testing.
- Laravel — Symlink Image Storage on Share Hosting Not Found Path
- PHP — Implement Google reCAPTCHA v2 Tutorial with Example
- Laravel 9 Generate Report Save as PDF Example
- Laravel Estimate Article Reading in Minutes
- Laravel 9 Add Google reCaptcha v2 Example
Author
Founder of CamboTutorial.com, I am happy to share my knowledge related to programming that can help other people. I love write tutorial related to PHP, Laravel, Python, Java, Android Developement, all published post are make simple and easy to understand for beginner. Follow him