├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE │ └── bug----.md ├── .gitignore ├── LICENSE ├── README-EN.md ├── README.md ├── app.jks ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── azhon │ │ └── app │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── azhon │ │ │ └── app │ │ │ ├── MainActivity.kt │ │ │ └── MyDownload.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_dialog.png │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-en-rUS │ │ └── strings.xml │ │ ├── values-night │ │ └── themes.xml │ │ ├── values-zh-rTW │ │ └── strings.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── azhon │ └── app │ └── ExampleUnitTest.kt ├── appupdate-no-op ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── gradle.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── azhon │ │ └── appupdate │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── azhon │ │ └── appupdate │ │ ├── base │ │ ├── BaseHttpDownloadManager.kt │ │ └── bean │ │ │ └── DownloadStatus.kt │ │ ├── listener │ │ ├── OnButtonClickListener.kt │ │ ├── OnDownloadListener.kt │ │ └── OnDownloadListenerAdapter.kt │ │ ├── manager │ │ └── DownloadManager.kt │ │ └── util │ │ └── ApkUtil.kt │ └── test │ └── java │ └── com │ └── azhon │ └── appupdate │ └── ExampleUnitTest.kt ├── appupdate ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── gradle.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── azhon │ │ └── appupdate │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── azhon │ │ │ └── appupdate │ │ │ ├── base │ │ │ ├── BaseHttpDownloadManager.kt │ │ │ └── bean │ │ │ │ └── DownloadStatus.kt │ │ │ ├── config │ │ │ ├── AppUpdateFileProvider.kt │ │ │ └── Constant.kt │ │ │ ├── listener │ │ │ ├── LifecycleCallbacksAdapter.kt │ │ │ ├── OnButtonClickListener.kt │ │ │ ├── OnDownloadListener.kt │ │ │ └── OnDownloadListenerAdapter.kt │ │ │ ├── manager │ │ │ ├── DownloadManager.kt │ │ │ └── HttpDownloadManager.kt │ │ │ ├── service │ │ │ └── DownloadService.kt │ │ │ ├── util │ │ │ ├── ApkUtil.kt │ │ │ ├── DensityUtil.kt │ │ │ ├── FileUtil.kt │ │ │ ├── LogUtil.kt │ │ │ └── NotificationUtil.kt │ │ │ └── view │ │ │ ├── NumberProgressBar.java │ │ │ └── UpdateDialogActivity.kt │ └── res │ │ ├── drawable │ │ ├── app_update_bg_button.xml │ │ ├── app_update_bg_white_radius_6.xml │ │ ├── app_update_dialog_close.png │ │ └── app_update_dialog_default.png │ │ ├── layout │ │ └── app_update_dialog_update.xml │ │ ├── values-en-rUS │ │ └── strings.xml │ │ ├── values-zh-rTW │ │ └── strings.xml │ │ ├── values │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── app_update_file.xml │ └── test │ └── java │ └── com │ └── azhon │ └── appupdate │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img ├── en │ ├── en_1.png │ ├── en_2.png │ ├── en_3.png │ ├── en_4.png │ ├── en_5.png │ ├── en_6.png │ └── en_7.png ├── logo.png ├── money.jpg ├── qq_group_0.jpg ├── qq_group_1.jpg └── zh │ ├── zh_1.png │ ├── zh_2.png │ ├── zh_3.png │ ├── zh_4.png │ ├── zh_5.png │ ├── zh_6.png │ └── zh_7.png ├── maven.gradle ├── maven_publish.sh └── settings.gradle /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | custom: ['https://github.com/azhon/AppUpdate#%E8%B5%9E%E8%B5%8F'] 4 | #github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 5 | #patreon: # Replace with a single Patreon username 6 | #open_collective: # Replace with a single Open Collective username 7 | #ko_fi: # Replace with a single Ko-fi username 8 | #tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 9 | #community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 10 | #liberapay: # Replace with a single Liberapay username 11 | #issuehunt: # Replace with a single IssueHunt username 12 | #otechie: # Replace with a single Otechie username 13 | #custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug----.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question submission 3 | about: bug、future、anything 4 | title: Write title 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **AppUpdate parameter** 11 | Screenshot `DownloadManager` configuration 12 | 13 | **Steps to reproduce** 14 | 15 | **Log or something else** 16 | 17 | **Software version** 18 | - Android Studio: 19 | - AppUpdate Version: 20 | - Device Brand: 21 | - Device Model: 22 | - Android Version: 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | local.properties 11 | /secret.gpg 12 | -------------------------------------------------------------------------------- /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 [azhon] 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. 202 | -------------------------------------------------------------------------------- /README-EN.md: -------------------------------------------------------------------------------- 1 | ## [中文 文档](https://github.com/azhon/AppUpdate/blob/main/README.md) 2 | 3 |

4 |

5 | 6 | 7 | 8 | 9 |

10 | 11 | ## The core logic of this library: 12 | #### 1、When `apkVersionCode()` is set the latest VersionCode, it will automatically judge whether to display the dialog, download and install 13 | - Adapt to Android 13 notification permission, and when set `showNotification(true)`, clicking the upgrade button will request notification permission, and the download will continue regardless of whether you agree or not 14 | - When set `forcedUpgrade(true)`,display dialog has progress bar 15 | #### 2、When `apkVersionCode()` is not set, it can be regarded as a downloader, which will only download and install 16 | #### 3、Since Android Q version restricts background apps from launching Activity, a notification will be sent to the notification bar when the download is complete (ignoring the showNotification value, you need to allow notifications to be sent) 17 | #### 4、[For more usage,click here](https://github.com/azhon/AppUpdate/blob/main/app/src/main/java/com/azhon/app/MainActivity.kt#L79) 18 | 19 | ### Related Docs Links 20 | - [Activity background starts](https://developer.android.google.cn/guide/components/activities/background-starts) 21 | - [Adapt notification](https://developer.android.google.cn/guide/topics/ui/notifiers/notifications?hl=zh-cn) 22 | 23 | ## Table of Contents 24 | 25 | * Rendering 26 | * Function introduction 27 | * Demo download experience 28 | * Steps for usage 29 | * Skills 30 | * Version update record 31 | * End 32 | 33 | ### Rendering 34 | 35 |   36 |   37 |   38 | 39 | 40 | ### Function introduction 41 | 42 | * [x] Support Java、Kotlin 43 | * [x] Support AndroidX 44 | * [x] Support for custom download process 45 | * [x] Support Android 4.1 and above 46 | * [x] Support notification progress display, adapt to Android 13 47 | * [x] Support Chinese/Traditional/English 48 | * [x] Support for custom built-in dialog styles 49 | * [x] Support for canceling the download (if the notification bar message is sent, it will be removed) 50 | * [x] Support download completion Delete old APK file after opening new version 51 | * [x] Download using HttpURLConnection, no other third-party framework is integrated 52 | 53 | ### [Demo download experience](https://github.com/azhon/AppUpdate/releases/tag/demo) 54 | 55 | ### Steps for usage 56 | 57 | #### Step1:`app/build.gradle` 58 | 59 | ```groovy 60 | implementation 'io.github.azhon:appupdate:4.3.6' 61 | ``` 62 |
63 | Since in-app updates are prohibited by GooglePlay policy, it can be handled in productFlavors 64 | 65 | - [GooglePlay policy](https://support.google.com/googleplay/android-developer/answer/9888379?hl=en&ref_topic=9877467) 66 | - Library provides a version without no operation[Click see more](https://github.com/azhon/AppUpdate/blob/main/app/build.gradle) 67 | ```groovy 68 | android { 69 | //... 70 | productFlavors { 71 | other {} 72 | googlePlay {} 73 | } 74 | } 75 | 76 | dependencies { 77 | otherImplementation 'io.github.azhon:appupdate:latest-version' 78 | googlePlayImplementation 'io.github.azhon:appupdate-no-op:latest-version' 79 | } 80 | ``` 81 |
82 | 83 | #### Step2:Create `DownloadManager` 84 | 85 |
86 | Kotlin 87 | 88 | ```java 89 | val manager = DownloadManager.Builder(this).run { 90 | apkUrl("your apk url") 91 | apkName("appupdate.apk") 92 | smallIcon(R.mipmap.ic_launcher) 93 | //If this parameter is set, it will automatically determine whether to show dialog 94 | apkVersionCode(2) 95 | apkVersionName('v4.2.2') 96 | apkSize("7.7MB") 97 | apkDescription("description...") 98 | //Optional parameters... 99 | build() 100 | } 101 | manager?.download() 102 | ``` 103 |
104 | 105 |
106 | Java 107 | 108 | ```java 109 | DownloadManager manager = new DownloadManager.Builder(this) 110 | .apkUrl("your apk url") 111 | .apkName("appupdate.apk") 112 | .smallIcon(R.mipmap.ic_launcher) 113 | //If this parameter is set, it will automatically determine whether to show dialog 114 | .apkVersionCode(2) 115 | .apkVersionName("v4.2.2") 116 | .apkSize("7.7MB") 117 | .apkDescription("description...") 118 | //Optional parameters... 119 | .build(); 120 | manager.download(); 121 | ``` 122 |
123 | 124 | #### Step3:ProGuard Rules 125 | 126 | ```groovy 127 | -keep public class * extends android.app.Activity 128 | -keep public class * extends android.app.Service 129 | ``` 130 | 131 | ### Skills 132 | 133 | * Internationalization support, other languages only need to take the same name in the corresponding `string.xml` 134 | * To view the Log, you only need to filter the Tag at the beginning of `AppUpdate` 135 | * Download completed Delete old APK file after opening new version 136 | 137 | ```java 138 | //Old version apk file save path 139 | val result = ApkUtil.deleteOldApk(this, "${externalCacheDir?.path}/appupdate.apk") 140 | ``` 141 | 142 | * Tips: The contents of the upgrade dialog can be swiped up and down! 143 | * If you need to implement your own set of download process, you only need to `extends` `BaseHttpDownloadManager`. 144 | 145 | ```java 146 | class MyDownload : BaseHttpDownloadManager() {} 147 | ``` 148 | 149 | ### Version update record 150 | 151 | * v4.3.6(2024/10/22) 152 | 153 | * [Opt] Change DownloadManager release() to public 154 | 155 | #### [More update records click here to view](https://github.com/azhon/AppUpdate/wiki/Home) 156 | 157 | ### End 158 | 159 | * If you encounter problems during use, please feel free to ask Issues. 160 | * If you have any good suggestions, you can also mention Issues or send email to: azhon.cn@gmail.com. 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## [English Doc](https://github.com/azhon/AppUpdate/blob/main/README-EN.md) 2 | 3 |

4 |

5 | 6 | 7 | 8 | 9 |

10 | 11 | ## 如果你是Flutter,请使用[flutter_app_update](https://github.com/azhon/flutter_app_update) 12 | 13 | > [!NOTE] 14 | > ### 本库核心逻辑(必读): 15 | > #### 1、当调用了`apkVersionCode()`设置了最新的VersionCode,则内部会自动判断是否显示对话框、下载和安装 16 | > - 适配Android 13通知运行权限,且当设置`showNotification(true)`时,点击对话框的升级按钮会申请通知栏权限,无论是否同意都将会继续下载 17 | > - 当设置强制更新`forcedUpgrade(true)`时,显示的对话框会显示下载进度条 18 | > #### 2、当没有调用`apkVersionCode()`,就可以把它当成一个下载器,内部只会进行下载和安装 19 | > #### 3、由于Android 10限制后台应用启动Activity,所以下载完成会发送一个通知至通知栏(忽略showNotification的值,需要允许发送通知) 20 | > #### 4、[更多用法请点此查看](https://github.com/azhon/AppUpdate/blob/main/app/src/main/java/com/azhon/app/MainActivity.kt#L79) 21 | 22 | ### 如果有需要使用[UpgradeLink](http://upgrade.toolsetlink.com)的可以[查阅此文档](http://upgrade.toolsetlink.com/upgrade/example/android-appupdate-example.html) 23 | 24 | ### 相关文档链接 25 | - [限制后台启动Activity](https://developer.android.google.cn/guide/components/activities/background-starts) 26 | - [通知栏适配](https://developer.android.google.cn/guide/topics/ui/notifiers/notifications?hl=zh-cn) 27 | 28 | ## 目录 29 | 30 | * [效果图](#效果图) 31 | * [功能介绍](#功能介绍) 32 | * [Demo下载体验](#demo下载体验) 33 | * [扫码加入QQ群](#扫码加入qq群) 34 | * [使用步骤](#使用步骤) 35 | * [使用技巧](#使用技巧) 36 | * [常见问题](#常见问题) 37 | * [版本更新记录](#版本更新记录) 38 | * [赞赏](#赞赏) 39 | 40 | ### 效果图 41 | 42 |   43 |   44 |   45 | 46 | 47 | ### 功能介绍 48 | 49 | * [x] 支持Java、Kotlin 50 | * [x] 支持AndroidX 51 | * [x] 支持后台下载 52 | * [x] 支持强制更新 53 | * [x] 支持自定义下载过程 54 | * [x] 支持Android4.1及以上版本 55 | * [x] 支持通知栏进度条展示,适配到Android 13 56 | * [x] 支持中文/繁体/英文语言(国际化) 57 | * [x] 支持自定义内置对话框样式 58 | * [x] 支持取消下载(如果发送了通知栏消息,则会移除) 59 | * [x] 支持下载完成,打开新版本后删除旧安装包文件 60 | * [x] 不需要申请存储权限 61 | * [x] 使用HttpURLConnection下载,未集成其他第三方框架 62 | 63 | ### Demo下载体验 64 | 65 | [点击下载Demo进行体验](https://github.com/azhon/AppUpdate/releases/tag/demo) 66 | 67 | ### 扫码加入QQ群 68 | - 或者添加加微信:hb958460248(备注 AppUpdate) 69 | - 611136880 70 | - 828385813(已满) 71 | 72 | 73 | 74 | 75 | ### 使用步骤 76 | 77 | #### 第一步:`app/build.gradle`添加依赖 78 | 79 | ```groovy 80 | implementation 'io.github.azhon:appupdate:4.3.6' 81 | ``` 82 | 83 |
84 | 由于GooglePlay政策禁止应用内更新,所以可以通过多渠道的方式进处理 85 | 86 | - [GooglePlay政策](https://support.google.com/googleplay/android-developer/answer/9888379?hl=en&ref_topic=9877467) 87 | - 本库提供了一个没有任何实现的版本[点击查看详细内容](https://github.com/azhon/AppUpdate/blob/main/app/build.gradle) 88 | ```groovy 89 | android { 90 | //... 91 | productFlavors { 92 | other {} 93 | googlePlay {} 94 | } 95 | } 96 | 97 | dependencies { 98 | otherImplementation 'io.github.azhon:appupdate:latest-version' 99 | googlePlayImplementation 'io.github.azhon:appupdate-no-op:latest-version' 100 | } 101 | ``` 102 |
103 | 104 | #### 第二步:创建`DownloadManager` 105 | 106 |
107 | Kotlin 108 | 109 | ```java 110 | val manager = DownloadManager.Builder(this).run { 111 | apkUrl("your apk url") 112 | apkName("appupdate.apk") 113 | smallIcon(R.mipmap.ic_launcher) 114 | //设置了此参数,那么内部会自动判断是否需要显示更新对话框,否则需要自己判断是否需要更新 115 | apkVersionCode(2) 116 | //同时下面三个参数也必须要设置 117 | apkVersionName('v4.2.2') 118 | apkSize("7.7MB") 119 | apkDescription("更新描述信息(取服务端返回数据)") 120 | //省略一些非必须参数... 121 | build() 122 | } 123 | manager?.download() 124 | ``` 125 |
126 | 127 |
128 | Java 129 | 130 | ```java 131 | DownloadManager manager = new DownloadManager.Builder(this) 132 | .apkUrl("your apk url") 133 | .apkName("appupdate.apk") 134 | .smallIcon(R.mipmap.ic_launcher) 135 | //设置了此参数,那么内部会自动判断是否需要显示更新对话框,否则需要自己判断是否需要更新 136 | .apkVersionCode(2) 137 | //同时下面三个参数也必须要设置 138 | .apkVersionName("v4.2.2") 139 | .apkSize("7.7MB") 140 | .apkDescription("更新描述信息(取服务端返回数据)") 141 | //省略一些非必须参数... 142 | .build(); 143 | manager.download(); 144 | ``` 145 |
146 | 147 | #### 第三步:混淆打包,只需保持`Activity`、`Service`不混淆 148 | 149 | ```groovy 150 | -keep public class * extends android.app.Activity 151 | -keep public class * extends android.app.Service 152 | ``` 153 | 154 | ### 使用技巧 155 | 156 | * 框架内部支持国际化(其他语言只需要在对应的`string.xml`中取相同的名字即可) 157 | * 如果你需要修改框架内部的一些文字,你只需要在`string.xml`中取相同的名字即可以覆盖框架内设定的 158 | * 查看版本库中的Log只需要过滤`AppUpdate`开头的Tag 159 | * 支持校验安装包的MD5避免重复下载,只需要`Builder`设置安装包的MD5即可 160 | * 下载完成 打开新版本后删除旧安装包文件 161 | 162 | ```java 163 | //旧版本apk的文件保存地址 164 | val result = ApkUtil.deleteOldApk(this, "${externalCacheDir?.path}/appupdate.apk") 165 | ``` 166 | 167 | * 温馨提示:升级对话框中的内容是可以上下滑动的哦! 168 | * 如果需要实现自己一套下载过程,只需要继承`BaseHttpDownloadManager` 169 | 170 | ```java 171 | class MyDownload : BaseHttpDownloadManager() {} 172 | ``` 173 | ### 常见问题 174 | 175 | * App设置是横屏时下载完成无法拉起安装问题,可以在Manifest中对应的Activity添加如下代码 176 | 177 | ```xml 178 | android:configChanges="orientation|screenSize|keyboardHidden" 179 | ``` 180 | 181 | ### 版本更新记录 182 | 183 | * v4.3.6(2024/10/22) 184 | 185 | * [优化] 修改DownloadManager的release()函数访问权限 186 | 187 | * [更多更新记录点此查看](https://github.com/azhon/AppUpdate/wiki/Home) 188 | 189 | ### 赞赏 190 | > 如果这个库有帮助到你并且你很想支持库的后续开发和维护,那么你可以扫描下方二维码随意打赏我,我将不胜感激[赞赏列表](https://github.com/azhon/AppUpdate/wiki/%E8%B5%9E%E8%B5%8F%E5%88%97%E8%A1%A8) 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /app.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/azhon/AppUpdate/a7b0839870948d180b86d7aceaf946fd27a4739b/app.jks -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'org.jetbrains.kotlin.android' 4 | } 5 | 6 | android { 7 | namespace 'com.azhon.app' 8 | compileSdk rootProject.ext.compileSdk 9 | defaultConfig { 10 | applicationId "com.azhon.app" 11 | minSdk rootProject.ext.minSdk 12 | targetSdk rootProject.ext.targetSdk 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | flavorDimensions "versionCode" 19 | 20 | compileOptions { 21 | sourceCompatibility JavaVersion.VERSION_1_8 22 | targetCompatibility JavaVersion.VERSION_1_8 23 | } 24 | kotlinOptions { 25 | jvmTarget = '1.8' 26 | } 27 | 28 | productFlavors { 29 | other {} 30 | // googlePlay {} 31 | } 32 | signingConfigs { 33 | config { 34 | keyAlias 'appUpdate' 35 | keyPassword '123456' 36 | storeFile file('./../app.jks') 37 | storePassword '123456' 38 | } 39 | } 40 | buildTypes { 41 | release { 42 | minifyEnabled false 43 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 44 | signingConfig signingConfigs.config 45 | } 46 | debug { 47 | signingConfig signingConfigs.config 48 | } 49 | } 50 | } 51 | 52 | dependencies { 53 | otherImplementation project(':appupdate') 54 | // googlePlayImplementation project(':appupdate-no-op') 55 | 56 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1" 57 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1" 58 | implementation 'androidx.core:core-ktx:1.7.0' 59 | implementation 'androidx.appcompat:appcompat:1.4.2' 60 | implementation 'com.google.android.material:material:1.5.0' 61 | testImplementation 'junit:junit:4.13.2' 62 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 63 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 64 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /app/src/androidTest/java/com/azhon/app/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.azhon.app 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.azhon.app", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/azhon/app/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.azhon.app 2 | 3 | import android.graphics.Color 4 | import android.os.Bundle 5 | import android.util.Log 6 | import android.view.View 7 | import android.widget.Button 8 | import android.widget.ProgressBar 9 | import android.widget.TextView 10 | import androidx.appcompat.app.AlertDialog 11 | import androidx.appcompat.app.AppCompatActivity 12 | import com.azhon.appupdate.listener.OnButtonClickListener 13 | import com.azhon.appupdate.listener.OnDownloadListenerAdapter 14 | import com.azhon.appupdate.manager.DownloadManager 15 | import com.azhon.appupdate.util.ApkUtil 16 | 17 | /** 18 | * createDate: 2022/04/08 on 14:52 19 | * desc: 20 | * 21 | * @author azhon 22 | */ 23 | 24 | class MainActivity : AppCompatActivity(), View.OnClickListener, OnButtonClickListener { 25 | 26 | companion object { 27 | private const val TAG = "MainActivity" 28 | } 29 | 30 | private val url = "https://downv6.qq.com/qqweb/QQ_1/android_apk/Android_9.0.81_64.apk" 31 | private val apkName = "appupdate.apk" 32 | private var manager: DownloadManager? = null 33 | private lateinit var tvPercent: TextView 34 | private lateinit var progressBar: ProgressBar 35 | 36 | override fun onCreate(savedInstanceState: Bundle?) { 37 | super.onCreate(savedInstanceState) 38 | setContentView(R.layout.activity_main) 39 | title = getString(R.string.app_title) 40 | progressBar = findViewById(R.id.number_progress_bar) 41 | tvPercent = findViewById