├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── enhancement.md └── pull_request_template.md ├── .gitignore ├── .idea ├── checkstyle-idea.xml ├── codeStyles │ └── Project.xml ├── compiler.xml ├── copyright │ ├── Apache_2_0.xml │ └── profiles_settings.xml ├── encodings.xml ├── kotlinc.xml ├── markdown-navigator.xml └── markdown-navigator │ └── profiles_settings.xml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hyperdevs │ │ └── appupdateshelper │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── kotlin │ │ └── com │ │ │ └── hyperdevs │ │ │ └── appupdateshelper │ │ │ └── app │ │ │ ├── MainActivity.kt │ │ │ ├── fake │ │ │ └── FakeUpdateActivity.kt │ │ │ ├── flexible │ │ │ └── FlexibleUpdateActivity.kt │ │ │ ├── fragment │ │ │ ├── FragmentUpdateActivity.kt │ │ │ └── FragmentUpdateFragment.kt │ │ │ ├── immediate │ │ │ └── ImmediateUpdateActivity.kt │ │ │ └── misc │ │ │ ├── ActivityExtensions.kt │ │ │ └── FragmentExtensions.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── fake_update_activity.xml │ │ ├── flexible_update_activity.xml │ │ ├── fragment_update_activity.xml │ │ ├── fragment_update_fragment.xml │ │ ├── immediate_update_activity.xml │ │ └── main_activity.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── hyperdevs │ └── appupdateshelper │ └── ExampleUnitTest.kt ├── build.gradle ├── checkstyle.xml ├── code-style.xml ├── debug.keystore ├── gradle.properties ├── gradle ├── properties_utils.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jitpack-android.gradle ├── jitpack.yml ├── lib ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hyperdevs │ │ └── appupdateshelper │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── hyperdevs │ │ │ └── appupdateshelper │ │ │ ├── AppUpdateInfoResult.java │ │ │ ├── AppUpdateInstallState.java │ │ │ ├── AppUpdatesHelper.java │ │ │ ├── ContextUtils.java │ │ │ ├── FakeAppUpdatesHelper.java │ │ │ ├── GetUpdateInfoListener.java │ │ │ └── InstallStateListener.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── hyperdevs │ └── appupdateshelper │ └── ExampleUnitTest.java └── settings.gradle /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This is a comment. 2 | # Each line is a file pattern followed by one or more owners. 3 | 4 | # Current code owners 5 | # @adriangl -> Adrián García 6 | 7 | * @adriangl -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a bug report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: adriangl 7 | 8 | --- 9 | 10 | **Device and SW details** 11 | - Device: [e.g. Google Pixel 3] 12 | - OS: [e.g. Android 9] 13 | - Library Version [e.g. 1.0.0] 14 | 15 | **Conditions for the library to work** 16 | - [ ] I have set the package name of the app to **exactly** the one I'd like to test in-app updates with. 17 | - [ ] I have signed the app with the same key that I used to sign the app I want to test in-app updates with. 18 | - [ ] I've ensured that any of my Google accounts in my test device has access to said app in Google Play Store. 19 | - [ ] The Google Play Store displays updates for the app I want to use to test in-app updates with. 20 | 21 | **Summary and background of the bug** 22 | A clear and concise description of what the bug is. 23 | 24 | **Steps to reproduce** 25 | Steps to reproduce the behavior: 26 | 1. Go to '...' 27 | 2. Click on '...' 28 | 3. Scroll down to '...' 29 | 4. See error 30 | 31 | Also attach notes or stack traces if applicable. 32 | 33 | **Expected behavior** 34 | A clear and concise description of what you expected to happen. 35 | 36 | **Current behavior** 37 | The summary of what currently happens in your use case. 38 | 39 | **Screenshots** 40 | If applicable, add screenshots to help explain your problem. 41 | 42 | **Additional context** 43 | Add any other context about the problem here. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Enhancement 3 | about: Create a report to propose new features and improvements 4 | title: '' 5 | labels: enhancement 6 | assignees: adriangl 7 | 8 | --- 9 | 10 | **Summary and context of the enhancement** 11 | A clear and concise description of what the bug is. 12 | 13 | **Suggested implementation** 14 | Add suggestions about how the enhancement should be implemented. 15 | 16 | **Additional documentation** 17 | Useful links to review the enhancement. -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ### Github issue (if applies) 2 | https://github.com/bq/AppUpdatesHelper/issues/change_me_issue_number 3 | 4 | ### PR's key points 5 | 6 | ### How to review this PR? 7 | 8 | ### Related Issues 9 | 10 | ### Definition of Done 11 | - [ ] Tests pass 12 | - [ ] Works with Proguard 13 | - [ ] There is no outcommented or debug code left (if there is a good reason, use a // FIXME: comment or // TODO: comment and create a follow-up issue) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | .idea/caches 43 | .idea/modules.xml 44 | .idea/misc.xml 45 | .idea/jarRepositories.xml 46 | .idea/vcs.xml 47 | 48 | # Keystore files 49 | *.jks 50 | 51 | # External native build folder generated in Android Studio 2.2 and later 52 | .externalNativeBuild 53 | 54 | # Google Services (e.g. APIs or Firebase) 55 | google-services.json 56 | 57 | # Freeline 58 | freeline.py 59 | freeline/ 60 | freeline_project_description.json 61 | 62 | # App configuration properties 63 | app_config.properties -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 20 | 21 | 22 | 23 | 25 | 26 | 27 |
28 | 29 | 30 | 31 | xmlns:android 32 | 33 | ^$ 34 | 35 | 36 | 37 |
38 |
39 | 40 | 41 | 42 | xmlns:.* 43 | 44 | ^$ 45 | 46 | 47 | BY_NAME 48 | 49 |
50 |
51 | 52 | 53 | 54 | .*:id 55 | 56 | http://schemas.android.com/apk/res/android 57 | 58 | 59 | 60 |
61 |
62 | 63 | 64 | 65 | .*:name 66 | 67 | http://schemas.android.com/apk/res/android 68 | 69 | 70 | 71 |
72 |
73 | 74 | 75 | 76 | name 77 | 78 | ^$ 79 | 80 | 81 | 82 |
83 |
84 | 85 | 86 | 87 | style 88 | 89 | ^$ 90 | 91 | 92 | 93 |
94 |
95 | 96 | 97 | 98 | .* 99 | 100 | ^$ 101 | 102 | 103 | BY_NAME 104 | 105 |
106 |
107 | 108 | 109 | 110 | .* 111 | 112 | http://schemas.android.com/apk/res/android 113 | 114 | 115 | ANDROID_ATTRIBUTE_ORDER 116 | 117 |
118 |
119 | 120 | 121 | 122 | .* 123 | 124 | .* 125 | 126 | 127 | BY_NAME 128 | 129 |
130 |
131 |
132 |
133 |
134 |
-------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/copyright/Apache_2_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | 22 | 23 | ## [Unreleased] 24 | ### Added 25 | - No new features! 26 | ### Changed 27 | - No changed features! 28 | ### Deprecated 29 | - No deprecated features! 30 | ### Removed 31 | - No removed features! 32 | ### Fixed 33 | - No fixed issues! 34 | ### Security 35 | - No security issues fixed! 36 | 37 | ## [2.1.4] - 2022-09-03 38 | ### Changed 39 | - Updated up to Android 14 40 | 41 | ## [2.0.0] - 2021-04-28 42 | ### Changed 43 | - Changed repo ownership to [hyperdevs-team](https://github.com/hyperdevs-team). Thanks [bq](https://github.com/bq) for all the work! 44 | - Changed package names from `com.bq.*` to `com.hyperdevs.*` 45 | - Updated dependencies 46 | 47 | ## [1.1.0] - 2020-11-05 48 | ### Added 49 | - Add in-app update stale status (added in `play-core` 1.6.5) 50 | - Add download progress in install listener (added in `play-core` 1.6.5) 51 | - Return in-app update priority set via Google Play Developer API (added in `play-core` 1.6.5) 52 | - More error codes tweaked (added in multiple `play-core` releases) 53 | - Set-up listeners from both `Activity` and `Fragment` 54 | - Add sample app configuration 55 | ### Changed 56 | - `play-core` library version upgrade to 1.8.2 57 | 58 | ## [1.0.2] - 2020-10-07 59 | ### Changed 60 | - `play-core` library version upgrade to 1.8.0 61 | - Bump library versions in both library and sample app 62 | 63 | ## [1.0.1] - 2019-06-26 64 | ### Added 65 | - Add automatic version name via Git tags and refactor versions 66 | ### Fixed 67 | - Fix import issues with api instead of implementation when importing `play-core` libs. 68 | 69 | ## [1.0.0] - 2019-06-20 70 | ### Added 71 | - Initial release. 72 | 73 | [Unreleased]: https://github.com/hyperdevs-team/android-app-updates-helper/compare/2.1.4...HEAD 74 | [2.1.4]: https://github.com/hyperdevs-team/android-app-updates-helper/compare/1.1.0...2.0.0 75 | [2.0.0]: https://github.com/hyperdevs-team/android-app-updates-helper/compare/1.1.0...2.0.0 76 | [1.1.0]: https://github.com/hyperdevs-team/android-app-updates-helper/compare/1.0.2...1.1.0 77 | [1.0.2]: https://github.com/hyperdevs-team/android-app-updates-helper/compare/1.0.1...1.0.2 78 | [1.0.1]: https://github.com/hyperdevs-team/android-app-updates-helper/compare/1.0.0...1.0.1 79 | [1.0.0]: https://github.com/hyperdevs-team/android-app-updates-helper/releases/tag/1.0.0 80 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to AppUpdatesHelper 2 | 3 | We love your input! We want to make contributing to this project as easy as possible, whether it's: 4 | 5 | - Reporting a bug 6 | - Submitting a fix 7 | - Proposing new features 8 | - Discussing the current state of the code 9 | 10 | ## We Develop with GitHub 11 | We use GitHub to host code, to track issues and feature requests, as well as to accept pull requests. 12 | 13 | ## Report bugs using Github's [issues](https://github.com/bq/AppUpdatesHelper/issues) 14 | We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/bq/AppUpdatesHelper/issues/new)! 15 | 16 | ## Code Changes Happen Through Pull Requests 17 | Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests: 18 | 19 | 1. Fork the repo and create your branch from `master`. 20 | 2. If you've added code that should be tested, add tests. 21 | 3. If you've changed APIs, update the documentation. 22 | 4. Make sure your code lints and passes the Checkstyle rules. 23 | 5. Issue that pull request! 24 | 25 | ## Any contributions you make will be under the Apache 2.0 Software License 26 | When you submit code changes, your submissions are understood to be under the same [Apache License 2.0](http://choosealicense.com/licenses/apache-2.0/) that covers the project. 27 | Feel free to contact the maintainers if that's a concern. 28 | 29 | ## Write bug reports with detail, background, and sample code 30 | **Great Bug Reports** tend to have: 31 | 32 | - A quick summary and/or background 33 | - Steps to reproduce 34 | - Be specific! 35 | - Give sample code if you can in order to reproduce the issue 36 | - Add the stack traces you find in case the library makes your app crash 37 | - What you expected would happen 38 | - What actually happens 39 | - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) 40 | 41 | ## Use a Consistent Coding Style 42 | We provide a [code-style](code-style.xml) and [checkstyle](checkstyle.xml) configuration files so you can ensure that all code is properly formatted according to our guidelines. 43 | Please be sure to use these files to format your files when submitting pull requests. 44 | 45 | ## References 46 | This document was adapted from the contribution guidelines proposed by [Brian A. Danielak](https://gist.github.com/briandk/3d2e8b3ec8daf5a27a62) which are itself based on the open-source contribution guidelines for [Facebook's Draft](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android App Updates Helper 2 | [![Release](https://jitpack.io/v/hyperdevs-team/android-app-updates-helper.svg)](https://jitpack.io/#hyperdevs-team/android-app-updates-helper) 3 | 4 | This utility library aims to help Android developers to use the [Google Play In-App Updates API](https://developer.android.com/guide/app-bundle/in-app-updates) in an easy way. 5 | 6 | > It's highly encouraged that you first read the [Google Play In-App Updates API](https://developer.android.com/guide/app-bundle/in-app-updates) documentation before using this library in order to understand the core concepts of the library. 7 | 8 | ## Setting Up 9 | In your main `build.gradle`, add [jitpack.io](https://jitpack.io/) repository in the `allprojects` block: 10 | 11 |
Groovy 12 | 13 | ```groovy 14 | allprojects { 15 | repositories { 16 | maven { url "https://jitpack.io" } 17 | } 18 | } 19 | ``` 20 |
21 | 22 |
Kotlin 23 | 24 | ```kotlin 25 | allprojects { 26 | repositories { 27 | maven(url = "https://jitpack.io") 28 | } 29 | } 30 | ``` 31 |
32 | 33 | 34 | Add the following dependencies to your app or library's `build.gradle`: 35 | 36 |
Groovy 37 | 38 | ```groovy 39 | dependencies { 40 | implementation "com.github.hyperdevs-team:android-app-updates-helper:2.0.0" 41 | } 42 | ``` 43 |
44 | 45 | 46 |
Kotlin 47 | 48 | ```kotlin 49 | dependencies { 50 | implementation("com.github.hyperdevs-team:android-app-updates-helper:2.0.0") 51 | } 52 | ``` 53 |
54 | 55 | You'll also need to add support for Java 8 in your project. To do so: 56 |
Groovy 57 | 58 | ```groovy 59 | android { 60 | compileOptions { 61 | sourceCompatibility JavaVersion.VERSION_1_8 62 | targetCompatibility JavaVersion.VERSION_1_8 63 | } 64 | kotlinOptions { 65 | jvmTarget = "1.8" 66 | } 67 | } 68 | ``` 69 |
70 | 71 |
Kotlin 72 | 73 | ```kotlin 74 | android { 75 | compileOptions { 76 | sourceCompatibility = JavaVersion.VERSION_1_8 77 | targetCompatibility = JavaVersion.VERSION_1_8 78 | } 79 | kotlinOptions { 80 | jvmTarget = "1.8" 81 | } 82 | } 83 | ``` 84 |
85 | 86 | ## How to use 87 | * Create a new _AppUpdatesHelper_. 88 | * Start listening for app update changes with _AppUpdatesHelper.startListening()_, for example in _Activity.onCreate()_ or in _Fragment.onViewCreated()_. 89 | * Stop listening for app update changes with _AppUpdatesHelper.stopListening()_ in _Activity.onDestroy()_ or in _Fragment.onDestroyView()_. 90 | * Request app update information with _AppUpdatesHelper.getAppUpdateInfo()_. 91 | * Request a flexible or immediate update with _AppUpdatesHelper.startFlexibleUpdate()_ or _AppUpdatesHelper.startImmediateUpdate()_ 92 | 93 | Check the [example app](app) for more implementation details about [flexible](app/src/main/kotlin/com/bq/appupdateshelper/flexible/FlexibleUpdateActivity.kt) 94 | and [immediate](app/src/main/kotlin/com/bq/appupdateshelper/immediate/ImmediateUpdateActivity.kt) updates. 95 | 96 | You can also use a [fake implementation](app/src/main/kotlin/com/bq/appupdateshelper/fake/FakeUpdateActivity.kt) to test in-app updates. 97 | 98 | Keep in mind that you may not see in-app updates if these conditions don't match: 99 | * The package name of the app is **exactly** the one you'd like to test in-app updates with. 100 | * The app must be signed with the same keys that you used to sign the app you want to test in-app updates with. 101 | * If the app is not published yet or you want to test with internal app sharing or closed tracks, 102 | ensure that any of your Google accounts in your device has access to said app in Google Play Store. 103 | * Check if the Google Play Store displays updates for the app you want to use to test in-app updates. 104 | 105 | Please ensure that all conditions apply when using this library in order to avoid unnecessary headaches. 106 | 107 | ### Using the example app 108 | In order to ease using the example app with the sample data of your own app, 109 | you can create an `app_config.properties` file in the root of the project with the following content: 110 | ```properties 111 | applicationId=your.application.id 112 | keystorePath=/full/path/to/your/keystore/file 113 | keystorePwd=your_keystore_password 114 | keystoreAlias=your_keystore_alias 115 | keystoreAliasPwd=your_keystore_alias_password 116 | ``` 117 | 118 | These values will be picked up by the compilation process of the example app 119 | and will set the application ID and signing configurations for you. 120 | 121 | ## Authors & Collaborators 122 | * **[Adrián García](https://github.com/adriangl)** - *Author and maintainer* 123 | * **[Daniel Sánchez Ceinos](https://github.com/danielceinos)** - *Contributor* 124 | 125 | ## Acknowledgements 126 | The work in this repository up to April 28th, 2021 was done by [bq](https://github.com/bq). 127 | Thanks for all the work!! 128 | 129 | ## License 130 | This project is licensed under the Apache Software License, Version 2.0. 131 | ``` 132 | Copyright (C) 2021 HyperDevs 133 | 134 | Copyright (C) 2019 BQ 135 | 136 | Licensed under the Apache License, Version 2.0 (the "License"); 137 | you may not use this file except in compliance with the License. 138 | You may obtain a copy of the License at 139 | 140 | http://www.apache.org/licenses/LICENSE-2.0 141 | 142 | Unless required by applicable law or agreed to in writing, software 143 | distributed under the License is distributed on an "AS IS" BASIS, 144 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 145 | See the License for the specific language governing permissions and 146 | limitations under the License. 147 | ``` 148 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 HyperDevs 3 | * 4 | * Copyright (C) 2019 BQ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | apply plugin: "com.android.application" 20 | 21 | apply plugin: "kotlin-android" 22 | 23 | apply plugin: "com.gladed.androidgitversion" 24 | 25 | apply from: "$rootDir/gradle/properties_utils.gradle" 26 | 27 | ext { 28 | /* 29 | ******************** 30 | * Android variables 31 | ******************** 32 | */ 33 | compile_sdk_version = 34 34 | min_sdk_version = 21 35 | target_sdk_version = 34 36 | build_tools_version = "34.0.0" 37 | } 38 | 39 | android { 40 | namespace "com.hyperdevs.appupdateshelper.app" 41 | compileSdk = compile_sdk_version 42 | buildToolsVersion = build_tools_version 43 | 44 | defaultConfig { 45 | /* 46 | * Change your application ID to the app you want to test with 47 | * 48 | * Requires configuration via app_config.properties file or injected via environment variables. 49 | * The loadEnvOrProperty will try to find the environment variable (in snake_case) or the 50 | * property in signing.properties (converted to camelCase) 51 | */ 52 | applicationId loadEnvOrProperty("APPLICATION_ID", "com.hyperdevs.appupdateshelper.app", "app_config.properties") 53 | minSdkVersion min_sdk_version 54 | targetSdkVersion target_sdk_version 55 | versionCode 1 56 | versionName androidGitVersion.name() 57 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 58 | } 59 | 60 | buildFeatures { 61 | viewBinding true 62 | } 63 | 64 | signingConfigs { 65 | /* 66 | * Local release signing configuration 67 | * 68 | * Requires configuration via app_config.properties file or injected via environment variables. 69 | * The loadEnvOrProperty will try to find the environment variable (in snake_case) or the 70 | * property in signing.properties (converted to camelCase) 71 | */ 72 | localRelease { 73 | storeFile file(loadEnvOrProperty("KEYSTORE_PATH", new File(rootDir, "debug.keystore").path, "app_config.properties")) 74 | storePassword loadEnvOrProperty("KEYSTORE_PWD", "android", "app_config.properties") 75 | keyAlias loadEnvOrProperty("KEYSTORE_ALIAS", "androiddebugkey", "app_config.properties") 76 | keyPassword loadEnvOrProperty("KEYSTORE_ALIAS_PWD", "android", "app_config.properties") 77 | } 78 | } 79 | 80 | buildTypes { 81 | debug { 82 | signingConfig signingConfigs.localRelease 83 | } 84 | 85 | release { 86 | minifyEnabled false 87 | proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" 88 | signingConfig signingConfigs.localRelease 89 | } 90 | } 91 | 92 | sourceSets.configureEach { 93 | java.srcDirs += "src/${name}/kotlin" 94 | } 95 | 96 | compileOptions { 97 | sourceCompatibility JavaVersion.VERSION_1_8 98 | targetCompatibility JavaVersion.VERSION_1_8 99 | } 100 | 101 | kotlinOptions { 102 | jvmTarget = "1.8" 103 | } 104 | } 105 | 106 | dependencies { 107 | implementation project(":lib") 108 | implementation fileTree(dir: "libs", include: ["*.jar"]) 109 | 110 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 111 | 112 | implementation "androidx.appcompat:appcompat:1.6.1" 113 | implementation "androidx.core:core-ktx:1.10.1" 114 | implementation "androidx.constraintlayout:constraintlayout:2.1.4" 115 | 116 | testImplementation "junit:junit:4.13.2" 117 | 118 | androidTestImplementation "androidx.test:runner:1.5.2" 119 | androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1" 120 | implementation "com.google.android.material:material:1.9.0" 121 | } 122 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/hyperdevs/appupdateshelper/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 HyperDevs 3 | * 4 | * Copyright (C) 2019 BQ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package com.hyperdevs.appupdateshelper 20 | 21 | import androidx.test.InstrumentationRegistry 22 | import androidx.test.runner.AndroidJUnit4 23 | 24 | import org.junit.Test 25 | import org.junit.runner.RunWith 26 | 27 | import org.junit.Assert.* 28 | 29 | /** 30 | * Instrumented test, which will execute on an Android device. 31 | * 32 | * See [testing documentation](http://d.android.com/tools/testing). 33 | */ 34 | @RunWith(AndroidJUnit4::class) 35 | class ExampleInstrumentedTest { 36 | @Test 37 | fun useAppContext() { 38 | // Context of the app under test. 39 | val appContext = InstrumentationRegistry.getTargetContext() 40 | assertEquals("com.bq.appupdateshelper", appContext.packageName) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 23 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/hyperdevs/appupdateshelper/app/MainActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 HyperDevs 3 | * 4 | * Copyright (C) 2019 BQ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package com.hyperdevs.appupdateshelper.app 20 | 21 | import android.os.Bundle 22 | import android.widget.Button 23 | import androidx.appcompat.app.AppCompatActivity 24 | import com.hyperdevs.appupdateshelper.app.databinding.MainActivityBinding 25 | import com.hyperdevs.appupdateshelper.app.fake.FakeUpdateActivity 26 | import com.hyperdevs.appupdateshelper.app.flexible.FlexibleUpdateActivity 27 | import com.hyperdevs.appupdateshelper.app.fragment.FragmentUpdateActivity 28 | import com.hyperdevs.appupdateshelper.app.immediate.ImmediateUpdateActivity 29 | 30 | class MainActivity : AppCompatActivity() { 31 | private lateinit var binding: MainActivityBinding 32 | 33 | private val immediateButton: Button 34 | get() = binding.immediateButton 35 | 36 | private val flexibleButton: Button 37 | get() = binding.flexibleButton 38 | 39 | private val fragmentButton: Button 40 | get() = binding.fragmentButton 41 | 42 | private val fakeButton: Button 43 | get() = binding.fakeButton 44 | 45 | override fun onCreate(savedInstanceState: Bundle?) { 46 | super.onCreate(savedInstanceState) 47 | binding = MainActivityBinding.inflate(layoutInflater).apply { 48 | setContentView(root) 49 | } 50 | 51 | immediateButton.setOnClickListener { 52 | startActivity(ImmediateUpdateActivity.newIntent(this)) 53 | } 54 | 55 | flexibleButton.setOnClickListener { 56 | startActivity(FlexibleUpdateActivity.newIntent(this)) 57 | } 58 | 59 | fragmentButton.setOnClickListener { 60 | startActivity(FragmentUpdateActivity.newIntent(this)) 61 | } 62 | 63 | fakeButton.setOnClickListener { 64 | startActivity(FakeUpdateActivity.newIntent(this)) 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/hyperdevs/appupdateshelper/app/fake/FakeUpdateActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 HyperDevs 3 | * 4 | * Copyright (C) 2019 BQ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package com.hyperdevs.appupdateshelper.app.fake 20 | 21 | import android.content.Context 22 | import android.content.Intent 23 | import android.os.Bundle 24 | import android.os.Handler 25 | import android.util.Log 26 | import android.widget.Button 27 | import androidx.appcompat.app.AppCompatActivity 28 | import com.hyperdevs.appupdateshelper.AppUpdateInfoResult 29 | import com.hyperdevs.appupdateshelper.AppUpdateInstallState.Status.* 30 | import com.hyperdevs.appupdateshelper.FakeAppUpdatesHelper 31 | import com.hyperdevs.appupdateshelper.app.databinding.FakeUpdateActivityBinding 32 | import com.hyperdevs.appupdateshelper.app.R 33 | import com.hyperdevs.appupdateshelper.app.misc.showToast 34 | import com.google.android.material.snackbar.Snackbar 35 | 36 | /** 37 | * Activity that illustrates the use of the [FakeAppUpdatesHelper] class of the lib to simulate 38 | * app updates in test environments. 39 | * 40 | * In this class we'll simulate a flexible update scenario. In order to understand how flexible 41 | * updates work, please review [com.hyperdevs.appupdateshelper.flexible.FlexibleUpdateActivity]. 42 | */ 43 | class FakeUpdateActivity : AppCompatActivity() { 44 | 45 | companion object { 46 | private const val TAG = "FakeUpdateActivity" 47 | fun newIntent(context: Context): Intent { 48 | return Intent(context, FakeUpdateActivity::class.java) 49 | } 50 | } 51 | 52 | private lateinit var fakeAppUpdatesHelper: FakeAppUpdatesHelper 53 | 54 | private lateinit var binding: FakeUpdateActivityBinding 55 | 56 | private val startUpdateButton: Button 57 | get() = binding.startUpdateButton 58 | 59 | override fun onCreate(savedInstanceState: Bundle?) { 60 | super.onCreate(savedInstanceState) 61 | 62 | binding = FakeUpdateActivityBinding.inflate(layoutInflater).apply { 63 | setContentView(root) 64 | } 65 | 66 | setTitle(R.string.activity_fake_update_title) 67 | 68 | fakeAppUpdatesHelper = FakeAppUpdatesHelper(this) 69 | 70 | fakeAppUpdatesHelper.startListening { installState -> 71 | 72 | Log.d(TAG, "Update install state: $installState") 73 | 74 | when (installState.status) { 75 | UNKNOWN -> { 76 | showToast("Unknown install state") 77 | } 78 | DENIED -> { 79 | showToast("The user denied the flexible update!") 80 | finish() 81 | } 82 | REQUIRES_UI_INTENT -> { 83 | showToast("The update needs an UI intent!") 84 | } 85 | UPDATE_ACCEPTED -> { 86 | showToast("The user accepted the update!") 87 | } 88 | PENDING -> { 89 | showToast("Waiting for update to start!") 90 | } 91 | DOWNLOADING -> { 92 | showToast("The update is downloading!") 93 | } 94 | DOWNLOADED -> { 95 | showToast("The update is downloading! Progress: ${installState.downloadProgress}") 96 | 97 | Snackbar.make(binding.root, "Install the update?", Snackbar.LENGTH_INDEFINITE) 98 | .apply { 99 | setAction("Install") { 100 | fakeAppUpdatesHelper.completeUpdate() 101 | 102 | // Fake installation process 103 | fakeAppUpdatesHelper.completeFakeUpdate() 104 | } 105 | } 106 | .show() 107 | } 108 | INSTALLING -> { 109 | showToast("The update is being installed!") 110 | } 111 | INSTALLED -> { 112 | showToast("The update has been installed!") 113 | } 114 | FAILED -> { 115 | showToast("The update failed! Reason: ${installState.errorCode}") 116 | 117 | Snackbar.make(binding.root, "Retry?", Snackbar.LENGTH_LONG) 118 | .apply { 119 | setAction("Retry") { 120 | fakeAppUpdatesHelper.startImmediateUpdate(this@FakeUpdateActivity) 121 | } 122 | } 123 | .show() 124 | } 125 | CANCELED -> { 126 | showToast("The user canceled the flexible update!") 127 | } 128 | } 129 | } 130 | 131 | startUpdateButton.setOnClickListener { 132 | // We're going to set-up the fake in order to simulate an available update 133 | fakeAppUpdatesHelper.configAvailableUpdate() 134 | 135 | fakeAppUpdatesHelper.getAppUpdateInfo { appUpdateInfoResult -> 136 | Log.d(TAG, "App update info: $appUpdateInfoResult") 137 | 138 | if (appUpdateInfoResult.isSuccessful) { 139 | when (appUpdateInfoResult.updateAvailability!!) { 140 | AppUpdateInfoResult.Availability.UNKNOWN -> { 141 | showToast("The state of the update is unknown!") 142 | } 143 | AppUpdateInfoResult.Availability.UPDATE_NOT_AVAILABLE -> { 144 | showToast("No update available!") 145 | } 146 | AppUpdateInfoResult.Availability.UPDATE_AVAILABLE -> { 147 | showToast("Update available!") 148 | if (appUpdateInfoResult.canInstallFlexibleUpdate()) { 149 | // Start the update flow 150 | showToast("Can install flexible update!") 151 | fakeAppUpdatesHelper.startFlexibleUpdate(this) 152 | 153 | // Start faking the update flow 154 | fakeAppUpdatesHelper.startFakeInstallFlow() 155 | } else { 156 | showToast("Can not install flexible update!") 157 | } 158 | } 159 | AppUpdateInfoResult.Availability.UPDATE_IN_PROGRESS -> { 160 | showToast("Update in progress!") 161 | } 162 | AppUpdateInfoResult.Availability.UPDATE_DOWNLOADED -> { 163 | showToast("Update downloaded!") 164 | fakeAppUpdatesHelper.completeUpdate() 165 | 166 | // Start faking installation process 167 | fakeAppUpdatesHelper.completeFakeUpdate() 168 | } 169 | } 170 | } else { 171 | showToast("The update info could not be retrieved, " + 172 | "cause: ${appUpdateInfoResult.exception!!.message}") 173 | } 174 | } 175 | } 176 | } 177 | 178 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 179 | super.onActivityResult(requestCode, resultCode, data) 180 | 181 | // We bind this but the fake will not launch an external activity, so it won't effect 182 | // the flow 183 | fakeAppUpdatesHelper.onUpdateStatusResult(requestCode, resultCode) 184 | } 185 | 186 | override fun onDestroy() { 187 | super.onDestroy() 188 | fakeAppUpdatesHelper.stopListening() 189 | } 190 | } 191 | 192 | private fun FakeAppUpdatesHelper.configAvailableUpdate() { 193 | setUpdateAvailable(12345) 194 | } 195 | 196 | private fun FakeAppUpdatesHelper.startFakeInstallFlow() { 197 | val handler = Handler() 198 | 199 | with(handler) { 200 | postDelayed({ userAcceptsUpdate() }, 0) 201 | postDelayed({ downloadStarts() }, 1000) 202 | postDelayed({ downloadCompletes() }, 4000) 203 | } 204 | } 205 | 206 | private fun FakeAppUpdatesHelper.completeFakeUpdate() { 207 | val handler = Handler() 208 | 209 | with(handler) { 210 | postDelayed({ installCompletes() }, 4000) 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/hyperdevs/appupdateshelper/app/flexible/FlexibleUpdateActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 HyperDevs 3 | * 4 | * Copyright (C) 2019 BQ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package com.hyperdevs.appupdateshelper.app.flexible 20 | 21 | import android.content.Context 22 | import android.content.Intent 23 | import android.os.Bundle 24 | import android.util.Log 25 | import android.widget.Button 26 | import androidx.appcompat.app.AppCompatActivity 27 | import com.hyperdevs.appupdateshelper.AppUpdateInfoResult 28 | import com.hyperdevs.appupdateshelper.AppUpdateInstallState.Status.* 29 | import com.hyperdevs.appupdateshelper.AppUpdatesHelper 30 | import com.hyperdevs.appupdateshelper.app.databinding.FlexibleUpdateActivityBinding 31 | import com.hyperdevs.appupdateshelper.app.R 32 | import com.hyperdevs.appupdateshelper.app.misc.showToast 33 | import com.google.android.material.snackbar.Snackbar 34 | 35 | /** 36 | * Activity that illustrates the use of the [AppUpdatesHelper] class of the lib start flexible 37 | * updates. 38 | */ 39 | class FlexibleUpdateActivity : AppCompatActivity() { 40 | 41 | companion object { 42 | private const val TAG = "FlexibleUpdateActivity" 43 | fun newIntent(context: Context): Intent { 44 | return Intent(context, FlexibleUpdateActivity::class.java) 45 | } 46 | } 47 | 48 | private lateinit var appUpdatesHelper: AppUpdatesHelper 49 | 50 | private lateinit var binding: FlexibleUpdateActivityBinding 51 | 52 | private val startUpdateButton: Button 53 | get() = binding.startUpdateButton 54 | 55 | override fun onCreate(savedInstanceState: Bundle?) { 56 | super.onCreate(savedInstanceState) 57 | binding = FlexibleUpdateActivityBinding.inflate(layoutInflater).apply { 58 | setContentView(root) 59 | } 60 | 61 | setTitle(R.string.activity_flexible_update_title) 62 | 63 | // Instantiate the app updates helper and start using it with startListening() 64 | appUpdatesHelper = AppUpdatesHelper(this) 65 | 66 | appUpdatesHelper.startListening { installState -> 67 | // The update process is tracked here from the moment the user clicks "Update" until the 68 | // app is fully installed 69 | Log.d(TAG, "Update install state: $installState") 70 | 71 | when (installState.status) { 72 | UNKNOWN -> { 73 | showToast("Unknown install state") 74 | } 75 | DENIED -> { 76 | // This should only be reached in immediate updates 77 | showToast("The user denied the flexible update!") 78 | finish() 79 | } 80 | REQUIRES_UI_INTENT -> { 81 | // The docs don't really say anything about this state or when it's triggered 82 | // so... 83 | showToast("The update needs an UI intent!") 84 | } 85 | UPDATE_ACCEPTED -> { 86 | // The user has accepted the update, so you can notify the user 87 | showToast("The user accepted the update!") 88 | } 89 | PENDING -> { 90 | showToast("Waiting for update to start!") 91 | } 92 | DOWNLOADING -> { 93 | showToast("The update is downloading! Progress: ${installState.downloadProgress}") 94 | } 95 | DOWNLOADED -> { 96 | showToast("The update has been downloaded!") 97 | // Prompt the user to install the update when we know that the update has been 98 | // downloaded successfully 99 | Snackbar.make(binding.root, "Install the update?", Snackbar.LENGTH_INDEFINITE) 100 | .apply { 101 | setAction("Install") { 102 | appUpdatesHelper.completeUpdate() 103 | } 104 | } 105 | .show() 106 | } 107 | INSTALLING -> { 108 | showToast("The update is being installed!") 109 | } 110 | INSTALLED -> { 111 | // Usually you won't get up to this state, since the app closes automatically 112 | // in the installation process. Anyway, it's not a bad practice to consider this 113 | // case 114 | showToast("The update has been installed!") 115 | } 116 | FAILED -> { 117 | // The installation failed for some reason, here you can retry the update 118 | // process if needed 119 | showToast("The update failed! Reason: ${installState.errorCode}") 120 | 121 | Snackbar.make(binding.root, "Retry?", Snackbar.LENGTH_LONG) 122 | .apply { 123 | setAction("Retry") { 124 | appUpdatesHelper.startFlexibleUpdate(this@FlexibleUpdateActivity) 125 | } 126 | } 127 | .show() 128 | } 129 | CANCELED -> { 130 | // This state is only reachable in flexible updates and it happens when the 131 | // user cancels a flexible update. There's no need to do anything in this case. 132 | showToast("The user canceled the flexible update!") 133 | } 134 | } 135 | } 136 | 137 | startUpdateButton.setOnClickListener { 138 | // Start the update flow by first checking if there's any update available for the app 139 | // in the Play Store using getAppUpdateInfo() 140 | appUpdatesHelper.getAppUpdateInfo { appUpdateInfoResult -> 141 | Log.d(TAG, "App update info: $appUpdateInfoResult") 142 | 143 | if (appUpdateInfoResult.isSuccessful) { 144 | // If the request went well, you can check the state of the app update 145 | when (appUpdateInfoResult.updateAvailability!!) { 146 | AppUpdateInfoResult.Availability.UNKNOWN -> { 147 | showToast("The state of the update is unknown!") 148 | } 149 | AppUpdateInfoResult.Availability.UPDATE_NOT_AVAILABLE -> { 150 | showToast("No update available!") 151 | } 152 | AppUpdateInfoResult.Availability.UPDATE_AVAILABLE -> { 153 | showToast("Update available!") 154 | // When we know that the update is available, we must check if we can 155 | // perform the desired type of update 156 | if (appUpdateInfoResult.canInstallFlexibleUpdate()) { 157 | // Start the update flow 158 | showToast("Can install flexible update!") 159 | appUpdatesHelper.startFlexibleUpdate(this) 160 | } else { 161 | showToast("Can not install flexible update!") 162 | } 163 | } 164 | AppUpdateInfoResult.Availability.UPDATE_IN_PROGRESS -> { 165 | // If the update is in progress, we don't need to jump to the flexible flow again 166 | showToast("Update in progress!") 167 | } 168 | AppUpdateInfoResult.Availability.UPDATE_DOWNLOADED -> { 169 | // The app update is downloaded, but the install flow has not started 170 | // yet, so complete the update 171 | showToast("Update downloaded!") 172 | appUpdatesHelper.completeUpdate() 173 | } 174 | } 175 | } else { 176 | showToast("The update info could not be retrieved, " + 177 | "cause: ${appUpdateInfoResult.exception!!.message}") 178 | } 179 | } 180 | } 181 | } 182 | 183 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 184 | super.onActivityResult(requestCode, resultCode, data) 185 | 186 | // We have to bind the helper to the activity results so it can properly dispatch some 187 | // update events 188 | appUpdatesHelper.onUpdateStatusResult(requestCode, resultCode) 189 | } 190 | 191 | override fun onDestroy() { 192 | // Stop listening for updates with stopListening() 193 | super.onDestroy() 194 | appUpdatesHelper.stopListening() 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/hyperdevs/appupdateshelper/app/fragment/FragmentUpdateActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 HyperDevs 3 | * 4 | * Copyright (C) 2019 BQ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package com.hyperdevs.appupdateshelper.app.fragment 20 | 21 | import android.content.Context 22 | import android.content.Intent 23 | import android.os.Bundle 24 | import androidx.appcompat.app.AppCompatActivity 25 | import com.hyperdevs.appupdateshelper.AppUpdatesHelper 26 | import com.hyperdevs.appupdateshelper.app.R 27 | import com.hyperdevs.appupdateshelper.app.databinding.FragmentUpdateActivityBinding 28 | 29 | /** 30 | * Activity that illustrates the use of the [AppUpdatesHelper] class of the lib to start flexible 31 | * updates in a fragment. 32 | */ 33 | class FragmentUpdateActivity : AppCompatActivity() { 34 | companion object { 35 | fun newIntent(context: Context): Intent { 36 | return Intent(context, FragmentUpdateActivity::class.java) 37 | } 38 | } 39 | 40 | private lateinit var binding: FragmentUpdateActivityBinding 41 | 42 | override fun onCreate(savedInstanceState: Bundle?) { 43 | super.onCreate(savedInstanceState) 44 | binding = FragmentUpdateActivityBinding.inflate(layoutInflater).apply { 45 | setContentView(root) 46 | } 47 | 48 | setTitle(R.string.activity_fragment_update_title) 49 | } 50 | } -------------------------------------------------------------------------------- /app/src/main/kotlin/com/hyperdevs/appupdateshelper/app/fragment/FragmentUpdateFragment.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 HyperDevs 3 | * 4 | * Copyright (C) 2019 BQ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package com.hyperdevs.appupdateshelper.app.fragment 20 | 21 | import android.content.Intent 22 | import android.os.Bundle 23 | import android.util.Log 24 | import android.view.LayoutInflater 25 | import android.view.View 26 | import android.view.ViewGroup 27 | import android.widget.Button 28 | import androidx.fragment.app.Fragment 29 | import com.hyperdevs.appupdateshelper.AppUpdateInfoResult 30 | import com.hyperdevs.appupdateshelper.AppUpdateInstallState 31 | import com.hyperdevs.appupdateshelper.AppUpdatesHelper 32 | import com.hyperdevs.appupdateshelper.app.databinding.FragmentUpdateFragmentBinding 33 | import com.hyperdevs.appupdateshelper.app.misc.showToast 34 | import com.google.android.material.snackbar.Snackbar 35 | 36 | /** 37 | * Fragment that illustrates the use of the [AppUpdatesHelper] class of the lib to start flexible 38 | * updates in a fragment. 39 | */ 40 | class FragmentUpdateFragment : Fragment() { 41 | companion object { 42 | private const val TAG = "FragmentUpdateFragment" 43 | 44 | fun newInstance(): FragmentUpdateFragment { 45 | val args = Bundle() 46 | 47 | val fragment = FragmentUpdateFragment() 48 | fragment.arguments = args 49 | return fragment 50 | } 51 | } 52 | 53 | private lateinit var appUpdatesHelper: AppUpdatesHelper 54 | 55 | private lateinit var binding: FragmentUpdateFragmentBinding 56 | 57 | private val startUpdateButton: Button 58 | get() = binding.startUpdateButton 59 | 60 | override fun onCreateView(inflater: LayoutInflater, 61 | container: ViewGroup?, 62 | savedInstanceState: Bundle?): View? = 63 | FragmentUpdateFragmentBinding.inflate(inflater, container, false) 64 | .also { binding = it }.root 65 | 66 | 67 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 68 | super.onViewCreated(view, savedInstanceState) 69 | // Instantiate the app updates helper and start using it with startListening() 70 | appUpdatesHelper = AppUpdatesHelper(requireContext()) 71 | 72 | appUpdatesHelper.startListening { installState -> 73 | // The update process is tracked here from the moment the user clicks "Update" until the 74 | // app is fully installed 75 | Log.d(TAG, "Update install state: $installState") 76 | 77 | when (installState.status) { 78 | AppUpdateInstallState.Status.UNKNOWN -> { 79 | showToast("Unknown install state") 80 | } 81 | AppUpdateInstallState.Status.DENIED -> { 82 | // This should only be reached in immediate updates 83 | showToast("The user denied the flexible update!") 84 | requireActivity().finish() 85 | } 86 | AppUpdateInstallState.Status.REQUIRES_UI_INTENT -> { 87 | // The docs don't really say anything about this state or when it's triggered 88 | // so... 89 | showToast("The update needs an UI intent!") 90 | } 91 | AppUpdateInstallState.Status.UPDATE_ACCEPTED -> { 92 | // The user has accepted the update, so you can notify the user 93 | showToast("The user accepted the update!") 94 | } 95 | AppUpdateInstallState.Status.PENDING -> { 96 | showToast("Waiting for update to start!") 97 | } 98 | AppUpdateInstallState.Status.DOWNLOADING -> { 99 | showToast("The update is downloading! Progress: ${installState.downloadProgress}") 100 | } 101 | AppUpdateInstallState.Status.DOWNLOADED -> { 102 | showToast("The update has been downloaded!") 103 | // Prompt the user to install the update when we know that the update has been 104 | // downloaded successfully 105 | Snackbar.make(binding.root, "Install the update?", Snackbar.LENGTH_INDEFINITE) 106 | .apply { 107 | setAction("Install") { 108 | appUpdatesHelper.completeUpdate() 109 | } 110 | } 111 | .show() 112 | } 113 | AppUpdateInstallState.Status.INSTALLING -> { 114 | showToast("The update is being installed!") 115 | } 116 | AppUpdateInstallState.Status.INSTALLED -> { 117 | // Usually you won't get up to this state, since the app closes automatically 118 | // in the installation process. Anyway, it's not a bad practice to consider this 119 | // case 120 | showToast("The update has been installed!") 121 | } 122 | AppUpdateInstallState.Status.FAILED -> { 123 | // The installation failed for some reason, here you can retry the update 124 | // process if needed 125 | showToast("The update failed! Reason: ${installState.errorCode}") 126 | 127 | Snackbar.make(binding.root, "Retry?", Snackbar.LENGTH_LONG) 128 | .apply { 129 | setAction("Retry") { 130 | appUpdatesHelper.startFlexibleUpdate(this@FragmentUpdateFragment) 131 | } 132 | } 133 | .show() 134 | } 135 | AppUpdateInstallState.Status.CANCELED -> { 136 | // This state is only reachable in flexible updates and it happens when the 137 | // user cancels a flexible update. There's no need to do anything in this case. 138 | showToast("The user canceled the flexible update!") 139 | } 140 | } 141 | } 142 | 143 | startUpdateButton.setOnClickListener { 144 | // Start the update flow by first checking if there's any update available for the app 145 | // in the Play Store using getAppUpdateInfo() 146 | appUpdatesHelper.getAppUpdateInfo { appUpdateInfoResult -> 147 | Log.d(TAG, "App update info: $appUpdateInfoResult") 148 | 149 | if (appUpdateInfoResult.isSuccessful) { 150 | // If the request went well, you can check the state of the app update 151 | when (appUpdateInfoResult.updateAvailability!!) { 152 | AppUpdateInfoResult.Availability.UNKNOWN -> { 153 | showToast("The state of the update is unknown!") 154 | } 155 | AppUpdateInfoResult.Availability.UPDATE_NOT_AVAILABLE -> { 156 | showToast("No update available!") 157 | } 158 | AppUpdateInfoResult.Availability.UPDATE_AVAILABLE -> { 159 | showToast("Update available!") 160 | // When we know that the update is available, we must check if we can 161 | // perform the desired type of update 162 | if (appUpdateInfoResult.canInstallFlexibleUpdate()) { 163 | // Start the update flow 164 | showToast("Can install flexible update!") 165 | appUpdatesHelper.startFlexibleUpdate(this) 166 | } else { 167 | showToast("Can not install flexible update!") 168 | } 169 | } 170 | AppUpdateInfoResult.Availability.UPDATE_IN_PROGRESS -> { 171 | // If the update is in progress, we don't need to jump to the flexible flow again 172 | showToast("Update in progress!") 173 | } 174 | AppUpdateInfoResult.Availability.UPDATE_DOWNLOADED -> { 175 | // The app update is downloaded, but the install flow has not started 176 | // yet, so complete the update 177 | showToast("Update downloaded!") 178 | appUpdatesHelper.completeUpdate() 179 | } 180 | } 181 | } else { 182 | showToast("The update info could not be retrieved, " + 183 | "cause: ${appUpdateInfoResult.exception!!.message}") 184 | } 185 | } 186 | } 187 | } 188 | 189 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 190 | super.onActivityResult(requestCode, resultCode, data) 191 | 192 | // We have to bind the helper to the activity results so it can properly dispatch some 193 | // update events 194 | appUpdatesHelper.onUpdateStatusResult(requestCode, resultCode) 195 | } 196 | 197 | override fun onDestroyView() { 198 | // Stop listening for updates with stopListening() 199 | super.onDestroyView() 200 | appUpdatesHelper.stopListening() 201 | } 202 | } -------------------------------------------------------------------------------- /app/src/main/kotlin/com/hyperdevs/appupdateshelper/app/immediate/ImmediateUpdateActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 HyperDevs 3 | * 4 | * Copyright (C) 2019 BQ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package com.hyperdevs.appupdateshelper.app.immediate 20 | 21 | import android.content.Context 22 | import android.content.Intent 23 | import android.os.Bundle 24 | import android.util.Log 25 | import android.widget.Button 26 | import androidx.appcompat.app.AppCompatActivity 27 | import com.hyperdevs.appupdateshelper.AppUpdateInfoResult 28 | import com.hyperdevs.appupdateshelper.AppUpdateInstallState.Status.* 29 | import com.hyperdevs.appupdateshelper.AppUpdatesHelper 30 | import com.hyperdevs.appupdateshelper.app.databinding.ImmediateUpdateActivityBinding 31 | import com.hyperdevs.appupdateshelper.app.R 32 | import com.hyperdevs.appupdateshelper.app.misc.showToast 33 | import com.google.android.material.snackbar.Snackbar 34 | 35 | /** 36 | * Activity that illustrates the use of the [AppUpdatesHelper] class of the lib start immediate 37 | * updates. 38 | */ 39 | class ImmediateUpdateActivity : AppCompatActivity() { 40 | 41 | companion object { 42 | private const val TAG = "ImmediateUpdateActivity" 43 | fun newIntent(context: Context): Intent { 44 | return Intent(context, ImmediateUpdateActivity::class.java) 45 | } 46 | } 47 | 48 | private lateinit var appUpdatesHelper: AppUpdatesHelper 49 | 50 | private lateinit var binding: ImmediateUpdateActivityBinding 51 | 52 | private val startUpdateButton: Button 53 | get() = binding.startUpdateButton 54 | 55 | override fun onCreate(savedInstanceState: Bundle?) { 56 | super.onCreate(savedInstanceState) 57 | binding = ImmediateUpdateActivityBinding.inflate(layoutInflater).apply { 58 | setContentView(root) 59 | } 60 | 61 | setTitle(R.string.activity_immediate_update_title) 62 | 63 | // Instantiate the app updates helper and start using it with startListening() 64 | appUpdatesHelper = AppUpdatesHelper(this) 65 | 66 | appUpdatesHelper.startListening { installState -> 67 | // The update process is tracked here from the moment the user clicks "Update" until the 68 | // app is fully installed 69 | Log.d(TAG, "Update install state: $installState") 70 | 71 | when (installState.status) { 72 | UNKNOWN -> { 73 | showToast("Unknown install state") 74 | } 75 | DENIED -> { 76 | // This state is only reachable in immediate updates, and it happens when the 77 | // user cancels an immediate update. Here you can finish your activity. 78 | showToast("The user denied the immediate update!") 79 | finish() 80 | } 81 | REQUIRES_UI_INTENT -> { 82 | // The docs don't really say anything about this state or when it's triggered 83 | // so... 84 | showToast("The update needs an UI intent!") 85 | } 86 | UPDATE_ACCEPTED -> { 87 | // The user has accepted the update, so you can notify the user 88 | // This is not guaranteed to arrive in immediate updates. 89 | showToast("The user accepted the update!") 90 | } 91 | PENDING -> { 92 | showToast("Waiting for update to start!") 93 | } 94 | DOWNLOADING -> { 95 | showToast("The update is downloading! Progress: ${installState.downloadProgress}") 96 | } 97 | DOWNLOADED -> { 98 | showToast("The update has been downloaded!") 99 | } 100 | INSTALLING -> { 101 | showToast("The update is being installed!") 102 | } 103 | INSTALLED -> { 104 | // Usually you won't get up to this state, since the app closes automatically 105 | // in the installation process. Anyway, it's not a bad practice to consider this 106 | // case 107 | showToast("The update has been installed!") 108 | } 109 | FAILED -> { 110 | // The installation failed for some reason, here you can retry the update 111 | // process if needed 112 | showToast("The update failed! Reason: ${installState.errorCode}") 113 | 114 | Snackbar.make(binding.root, "Retry?", Snackbar.LENGTH_LONG) 115 | .apply { 116 | setAction("Retry") { 117 | appUpdatesHelper.startImmediateUpdate(this@ImmediateUpdateActivity) 118 | } 119 | } 120 | .show() 121 | } 122 | CANCELED -> { 123 | // This state is only reachable in flexible updates. 124 | showToast("The user canceled the immediate update!") 125 | } 126 | } 127 | } 128 | 129 | startUpdateButton.setOnClickListener { 130 | // Start the update flow by first checking if there's any update available for the app 131 | // in the Play Store using getAppUpdateInfo() 132 | appUpdatesHelper.getAppUpdateInfo { appUpdateInfoResult -> 133 | Log.d(TAG, "App update info: $appUpdateInfoResult") 134 | 135 | if (appUpdateInfoResult.isSuccessful) { 136 | // If the request went well, you can check the state of the app update 137 | when (appUpdateInfoResult.updateAvailability!!) { 138 | AppUpdateInfoResult.Availability.UNKNOWN -> { 139 | showToast("The state of the update is unknown!") 140 | } 141 | AppUpdateInfoResult.Availability.UPDATE_NOT_AVAILABLE -> { 142 | showToast("No update available!") 143 | } 144 | AppUpdateInfoResult.Availability.UPDATE_AVAILABLE -> { 145 | showToast("Update available!") 146 | // When we know that the update is available, we must check if we can 147 | // perform the desired type of update 148 | if (appUpdateInfoResult.canInstallImmediateUpdate()) { 149 | // Start the update flow immediately 150 | showToast("Can install immediate update!") 151 | appUpdatesHelper.startImmediateUpdate(this) 152 | } else { 153 | showToast("Can not install immediate update!") 154 | } 155 | } 156 | AppUpdateInfoResult.Availability.UPDATE_IN_PROGRESS -> { 157 | // If the update is in progress, we can jump to the immediate flow again 158 | showToast("Update in progress!") 159 | appUpdatesHelper.startImmediateUpdate(this) 160 | } 161 | AppUpdateInfoResult.Availability.UPDATE_DOWNLOADED -> { 162 | // The app update is downloaded, but the install flow has not started 163 | // yet, so complete the update 164 | showToast("Update downloaded!") 165 | appUpdatesHelper.completeUpdate() 166 | } 167 | } 168 | } else { 169 | showToast("The update info could not be retrieved, " + 170 | "cause: ${appUpdateInfoResult.exception!!.message}") 171 | } 172 | } 173 | } 174 | } 175 | 176 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 177 | super.onActivityResult(requestCode, resultCode, data) 178 | 179 | // We have to bind the helper to the activity results so it can properly dispatch some 180 | // update events 181 | appUpdatesHelper.onUpdateStatusResult(requestCode, resultCode) 182 | } 183 | 184 | override fun onDestroy() { 185 | // Stop listening for updates with stopListening() 186 | super.onDestroy() 187 | appUpdatesHelper.stopListening() 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/hyperdevs/appupdateshelper/app/misc/ActivityExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 HyperDevs 3 | * 4 | * Copyright (C) 2019 BQ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package com.hyperdevs.appupdateshelper.app.misc 20 | 21 | import android.app.Activity 22 | import android.widget.Toast 23 | import androidx.annotation.StringRes 24 | 25 | /** 26 | * Displays a text as a toast in the current activity. 27 | * 28 | * @param text Text to display in the toast 29 | * @param duration Duration, one of [Toast.LENGTH_SHORT] or [Toast.LENGTH_LONG] 30 | */ 31 | fun Activity.showToast(text: String, duration: Int = Toast.LENGTH_SHORT) { 32 | Toast.makeText(this, text, duration).show() 33 | } 34 | 35 | /** 36 | * Displays a text as a toast in the current activity. 37 | * 38 | * @param stringResId Text to display in the toast as a string resource ID 39 | * @param duration Duration, one of [Toast.LENGTH_SHORT] or [Toast.LENGTH_LONG] 40 | */ 41 | fun Activity.showToast(@StringRes stringResId: Int, duration: Int = Toast.LENGTH_SHORT) { 42 | Toast.makeText(this, stringResId, duration).show() 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/hyperdevs/appupdateshelper/app/misc/FragmentExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 HyperDevs 3 | * 4 | * Copyright (C) 2019 BQ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package com.hyperdevs.appupdateshelper.app.misc 20 | 21 | import android.widget.Toast 22 | import androidx.annotation.StringRes 23 | import androidx.fragment.app.Fragment 24 | 25 | /** 26 | * Displays a text as a toast in the current fragment. 27 | * 28 | * @param text Text to display in the toast 29 | * @param duration Duration, one of [Toast.LENGTH_SHORT] or [Toast.LENGTH_LONG] 30 | */ 31 | fun Fragment.showToast(text: String, duration: Int = Toast.LENGTH_SHORT) { 32 | Toast.makeText(context, text, duration).show() 33 | } 34 | 35 | /** 36 | * Displays a text as a toast in the current fragment. 37 | * 38 | * @param stringResId Text to display in the toast as a string resource ID 39 | * @param duration Duration, one of [Toast.LENGTH_SHORT] or [Toast.LENGTH_LONG] 40 | */ 41 | fun Fragment.showToast(@StringRes stringResId: Int, duration: Int = Toast.LENGTH_SHORT) { 42 | Toast.makeText(context, stringResId, duration).show() 43 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 25 | 30 | 31 | 37 | 40 | 43 | 44 | 45 | 46 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 76 | 78 | 80 | 82 | 84 | 86 | 88 | 90 | 92 | 93 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fake_update_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 28 | 29 | 36 | 37 | 45 | 46 |