├── .gitignore
├── .travis.yml
├── README.md
├── README_UN.MD
├── README_V1.1.md
├── README_V1.md
├── build.gradle
├── gif
├── AllenVersionChecker.png
├── V2.gif
├── custom.gif
├── main.jpg
├── style1.png
├── style2.png
├── style3.png
├── style4.png
├── v2.jpg
└── versionparams.png
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library.jar
├── library
├── .gitignore
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── allenliu
│ │ └── versionchecklib
│ │ ├── callback
│ │ ├── APKDownloadListener.java
│ │ ├── CommitClickListener.java
│ │ ├── DialogDismissListener.java
│ │ ├── DownloadListener.java
│ │ └── OnCancelListener.java
│ │ ├── core
│ │ ├── JumpActivity.java
│ │ ├── VersionFileProvider.java
│ │ └── http
│ │ │ ├── AllenHttp.java
│ │ │ ├── FileCallBack.java
│ │ │ ├── HttpHeaders.java
│ │ │ ├── HttpParams.java
│ │ │ └── HttpRequestMethod.java
│ │ ├── utils
│ │ ├── ALog.java
│ │ ├── AllenEventBusUtil.java
│ │ ├── AppUtils.java
│ │ └── FileHelper.java
│ │ └── v2
│ │ ├── AllenVersionChecker.java
│ │ ├── builder
│ │ ├── BuilderManager.kt
│ │ ├── DownloadBuilder.java
│ │ ├── NotificationBuilder.java
│ │ ├── RequestVersionBuilder.java
│ │ └── UIData.java
│ │ ├── callback
│ │ ├── CustomDownloadFailedListener.java
│ │ ├── CustomDownloadingDialogListener.java
│ │ ├── CustomInstallListener.java
│ │ ├── CustomVersionDialogListener.java
│ │ ├── DownloadListenerKt.kt
│ │ ├── ForceUpdateListener.java
│ │ ├── LifecycleListener.kt
│ │ └── RequestVersionListener.java
│ │ ├── eventbus
│ │ ├── AllenEventType.java
│ │ ├── BaseEvent.java
│ │ └── CommonEvent.java
│ │ ├── net
│ │ ├── DownloadMangerV2.java
│ │ └── RequestVersionManager.java
│ │ └── ui
│ │ ├── AllenBaseActivity.kt
│ │ ├── DownloadFailedActivity.kt
│ │ ├── DownloadingActivity.kt
│ │ ├── NotificationHelper.kt
│ │ ├── UIActivity.kt
│ │ └── VersionService.kt
│ └── res
│ ├── drawable
│ └── progressbar_horizontal.xml
│ ├── layout
│ └── downloading_layout.xml
│ ├── values-en
│ └── strings.xml
│ ├── values
│ ├── colors.xml
│ ├── ids.xml
│ ├── strings.xml
│ └── styles.xml
│ └── xml
│ └── versionchecklib_file_paths.xml
├── sample
├── .gitignore
├── 1_1.apk
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── allenliu
│ │ └── sample
│ │ ├── MainActivity.java
│ │ ├── MyApplication.java
│ │ ├── v1
│ │ └── BaseDialog.java
│ │ └── v2
│ │ └── V2Activity.java
│ └── res
│ ├── drawable
│ ├── custom_bg.png
│ └── shape_corner.xml
│ ├── layout
│ ├── activity_custom_version_dialog.xml
│ ├── activity_custom_version_dialog_two.xml
│ ├── activity_main.xml
│ ├── activity_v1.xml
│ ├── activity_v2.xml
│ ├── custom.xml
│ ├── custom_dialog_one_layout.xml
│ ├── custom_dialog_two_layout.xml
│ ├── custom_download_failed_dialog.xml
│ └── custom_download_layout.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ ├── dialog1.jpg
│ ├── dialog2.jpg
│ ├── dialog3.jpg
│ ├── dialog4.jpg
│ ├── dialog5.jpg
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 |
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 | .idea
10 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | android:
3 | components:
4 | - tools
5 | - build-tools-24.0.2
6 | - android-24
7 | - extra-android-m2repository
8 | - extra-android-support
9 | before_install:
10 | - chmod +x gradlew
11 | script:
12 | - "./gradlew assembleRelease"
13 |
--------------------------------------------------------------------------------
/README_UN.MD:
--------------------------------------------------------------------------------
1 | ## CheckVersionLib[](https://jitpack.io/#AlexLiuSheng/CheckVersionLib)
2 | ## V2版震撼来袭,功能强大,链式编程,调用简单,集成轻松,扩展性强大
3 |
4 | 老规矩先看V2效果,这个版本最大的特点就是使用非常简单,相对于1.+版本
5 |
6 | ### 效果
7 |
8 |
9 | ### 特点
10 | - [x] 任何地方都可以调用
11 |
12 | - [x] **简单简单简单简单**(重要的话我说四遍)
13 |
14 | - [x] **扩展性强大**
15 |
16 | - [x] 所有具有升级功能的app均可使用,耶稣说的
17 |
18 | - [x] **更强大的自定义界面支持**
19 |
20 | - [x] 支持强制更新(一行代码)
21 |
22 | - [x] 支持静默下载 (一行代码)
23 |
24 | - [x] 适配到Android 13
25 |
26 | ### 导入
27 | ```
28 | allprojects {
29 | repositories {
30 | ...
31 | maven { url 'https://jitpack.io' }
32 | }
33 | }
34 | ```
35 |
36 | ```
37 | dependencies {
38 | implementation 'com.github.AlexLiuSheng:CheckVersionLib:2.4.2'
39 | }
40 | ```
41 |
42 | ### 使用
43 |
44 | 两种模式
45 |
46 | > 只使用下载模式
47 |
48 | 先来个最简单的调用
49 |
50 | ```
51 | AllenVersionChecker
52 | .getInstance()
53 | .downloadOnly(
54 | UIData.create().setDownloadUrl(downloadUrl)
55 | )
56 | .executeMission(context);
57 | ```
58 |
59 | `UIData`:UIData是一个Bundle,用于存放用于UI展示的一些数据,后面自定义界面时候可以拿来用
60 |
61 |
62 |
63 | > 请求服务器版本+下载
64 |
65 | 该模式最简单的使用
66 | ```
67 | AllenVersionChecker
68 | .getInstance()
69 | .requestVersion()
70 | .setRequestUrl(requestUrl)
71 | .request(new RequestVersionListener() {
72 | @Nullable
73 | @Override
74 | public UIData onRequestVersionSuccess(String result) {
75 | //拿到服务器返回的数据,解析,拿到downloadUrl和一些其他的UI数据
76 | ...
77 | //如果是最新版本直接return null
78 | return UIData.create().setDownloadUrl(downloadUrl);
79 | }
80 |
81 | @Override
82 | public void onRequestVersionFailure(String message) {
83 |
84 | }
85 | })
86 | .executeMission(context);
87 |
88 |
89 | ```
90 | 请求版本一些其他的http参数可以设置,如下
91 |
92 | ```
93 | AllenVersionChecker
94 | .getInstance()
95 | .requestVersion()
96 | .setHttpHeaders(httpHeader)
97 | .setRequestMethod(HttpRequestMethod.POSTJSON)
98 | .setRequestParams(httpParam)
99 | .setRequestUrl(requestUrl)
100 | .request(new RequestVersionListener() {
101 | @Nullable
102 | @Override
103 | public UIData onRequestVersionSuccess(String result) {
104 | //拿到服务器返回的数据,解析,拿到downloadUrl和一些其他的UI数据
105 | ...
106 | UIData uiData = UIData
107 | .create()
108 | .setDownloadUrl(downloadUrl)
109 | .setTitle(updateTitle)
110 | .setContent(updateContent);
111 | //放一些其他的UI参数,拿到后面自定义界面使用
112 | uiData.getVersionBundle().putString("key", "your value");
113 | return uiData;
114 |
115 | }
116 |
117 | @Override
118 | public void onRequestVersionFailure(String message) {
119 |
120 | }
121 | })
122 | .executeMission(context);
123 | ```
124 |
125 | ### 合适的地方关闭任务
126 | 为了避免不必要的内存泄漏,需要在合适的地方取消任务
127 | ```
128 | AllenVersionChecker.getInstance().cancelAllMission();
129 | ```
130 |
131 |
132 | 以上就是最基本的使用(库默认会有一套界面),如果还不满足项目需求,下面就可以用这个库来飙车了
133 |
134 | ### 一些其他的function设置
135 | 解释下,下面的builder叫`DownloadBuilder`
136 | ```
137 | DownloadBuilder builder=AllenVersionChecker
138 | .getInstance()
139 | .downloadOnly();
140 |
141 |
142 | or
143 |
144 |
145 |
146 | DownloadBuilder builder=AllenVersionChecker
147 | .getInstance()
148 | .requestVersion()
149 | .request()
150 | ```
151 | > 取消任务
152 |
153 | ```
154 | AllenVersionChecker.getInstance().cancelAllMission(this);
155 |
156 | ```
157 | > 静默下载
158 |
159 | ```
160 | builder.setSilentDownload(true); 默认false
161 | ```
162 | > 设置当前服务器最新的版本号,供库判断是否使用缓存
163 |
164 | - 缓存策略:如果本地有安装包,首先判断与当前运行的程序的versionCode是否不一致,然后判断是否有传入最新的
165 | versionCode,如果传入的versionCode大于本地的,重新从服务器下载,否则使用缓存
166 |
167 | ```
168 | builder.setNewestVersionCode(int); 默认null
169 | ```
170 | > 强制更新
171 |
172 | 设置此listener即代表需要强制更新,会在用户想要取消下载的时候回调
173 | 需要你自己关闭所有界面
174 | ```
175 | builder.setForceUpdateListener(() -> {
176 | forceUpdate();
177 | });
178 | ```
179 | **update in v2.2.1**
180 | 动态设置是否强制更新,如果使用本库来请求服务器,可以在回调时动态设置一些参数或者回调
181 | ```
182 | public UIData onRequestVersionSuccess(DownloadBuilder downloadBuilder,String result) {
183 | downloadBuilder.setForceUpdateListener(() -> {
184 | forceUpdate();
185 | });
186 | Toast.makeText(V2Activity.this, "request successful", Toast.LENGTH_SHORT).show();
187 | return crateUIData();
188 | }
189 | ```
190 | > 下载忽略本地缓存
191 |
192 | 如果本地有安装包缓存也会重新下载apk
193 |
194 | ```
195 | builder.setForceRedownload(true); 默认false
196 | ```
197 |
198 | > 是否显示下载对话框
199 | ```
200 | builder.setShowDownloadingDialog(false); 默认true
201 | ```
202 | > 是否显示通知栏
203 | ```
204 | builder.setShowNotification(false); 默认true
205 | ```
206 | > **以前台service运行(update in 2.2.2)**
207 | 推荐以前台服务运行更新,防止在后台时,服务被杀死
208 | ```
209 | builder.setRunOnForegroundService(true); 默认true
210 |
211 | ```
212 | > 自定义通知栏
213 | ```
214 | builder.setNotificationBuilder(
215 | NotificationBuilder.create()
216 | .setRingtone(true)
217 | .setIcon(R.mipmap.dialog4)
218 | .setTicker("custom_ticker")
219 | .setContentTitle("custom title")
220 | .setContentText(getString(R.string.custom_content_text))
221 | );
222 | ```
223 | > 是否显示失败对话框
224 |
225 | ```
226 | builder.setShowDownloadFailDialog(false); 默认true
227 | ```
228 | > 自定义下载路径
229 |
230 | ```
231 | builder.setDownloadAPKPath(address); 默认:/storage/emulated/0/AllenVersionPath/
232 | ```
233 | > 自定义下载文件名
234 | ```
235 | builder.setApkName(apkName); 默认:getPackageName()
236 | ```
237 | > 可以设置下载监听
238 |
239 | ```
240 | builder.setApkDownloadListener(new APKDownloadListener() {
241 | @Override
242 | public void onDownloading(int progress) {
243 |
244 | }
245 |
246 | @Override
247 | public void onDownloadSuccess(File file) {
248 |
249 | }
250 |
251 | @Override
252 | public void onDownloadFail() {
253 |
254 | }
255 | });
256 | ```
257 | > 设置取消监听
258 | 此回调会监听所有cancel事件
259 | ```
260 |
261 | builder.setOnCancelListener(() -> {
262 | Toast.makeText(V2Activity.this,"Cancel Hanlde",Toast.LENGTH_SHORT).show();
263 | });
264 | ```
265 | **如果想单独监听几种状态下的cancel,可像如下这样设置**
266 | - ` builder.setDownloadingCancelListener();`
267 | - `builder.setDownloadFailedCancelListener();`
268 | - `builder.setReadyDownloadCancelListener();`
269 |
270 | > 设置确定监听(**added after 2.2.2**)
271 |
272 | - ` builder.setReadyDownloadCommitClickListener();`
273 | - `builder.setDownloadFailedCommitClickListener();`
274 |
275 | > 静默下载+直接安装(不会弹出升级对话框)
276 | ```
277 | builder.setDirectDownload(true);
278 | builder.setShowNotification(false);
279 | builder.setShowDownloadingDialog(false);
280 | builder.setShowDownloadFailDialog(false);
281 | ```
282 | > 自定义安装回调
283 | ```
284 | setCustomDownloadInstallListener(CustomInstallListener customDownloadInstallListener)
285 | ```
286 |
287 | ### 自定义界面
288 |
289 | 自定义界面使用回调方式,开发者需要返回自己定义的Dialog(父类android.app)
290 |
291 | - 所有自定义的界面必须使用listener里面的context实例化
292 |
293 | - 界面展示的数据通过UIData拿
294 |
295 | > **自定义显示更新界面**
296 |
297 | 设置`CustomVersionDialogListener`
298 |
299 |
300 | - 定义此界面**必须**有一个确定下载的按钮,按钮id必须为`@id/versionchecklib_version_dialog_commit`
301 |
302 | - 如果有取消按钮(没有忽略本条要求),则按钮id必须为`@id/versionchecklib_version_dialog_cancel`
303 |
304 | eg.
305 |
306 | ```
307 | builder.setCustomVersionDialogListener((context, versionBundle) -> {
308 | BaseDialog baseDialog = new BaseDialog(context, R.style.BaseDialog, R.layout.custom_dialog_one_layout);
309 | //versionBundle 就是UIData,之前开发者传入的,在这里可以拿出UI数据并展示
310 | TextView textView = baseDialog.findViewById(R.id.tv_msg);
311 | textView.setText(versionBundle.getContent());
312 | return baseDialog;
313 | });
314 |
315 | ```
316 |
317 | > **自定义下载中对话框界面**
318 |
319 | 设置`CustomDownloadingDialogListener`
320 |
321 |
322 | - 如果此界面要设计取消操作(没有忽略),请务必将id设置为`@id/versionchecklib_loading_dialog_cancel`
323 |
324 |
325 | ```
326 | builder.setCustomDownloadingDialogListener(new CustomDownloadingDialogListener() {
327 | @Override
328 | public Dialog getCustomDownloadingDialog(Context context, int progress, UIData versionBundle) {
329 | BaseDialog baseDialog = new BaseDialog(context, R.style.BaseDialog, R.layout.custom_download_layout);
330 | return baseDialog;
331 | }
332 | //下载中会不断回调updateUI方法
333 | @Override
334 | public void updateUI(Dialog dialog, int progress, UIData versionBundle) {
335 | TextView tvProgress = dialog.findViewById(R.id.tv_progress);
336 | ProgressBar progressBar = dialog.findViewById(R.id.pb);
337 | progressBar.setProgress(progress);
338 | tvProgress.setText(getString(R.string.versionchecklib_progress, progress));
339 | }
340 | });
341 | ```
342 |
343 | > **自定义下载失败对话框**
344 |
345 | 设置CustomDownloadFailedListener
346 |
347 | - 如果有**重试**按钮请将id设置为`@id/versionchecklib_failed_dialog_retry`
348 |
349 | - 如果有 **确认/取消**按钮请将id设置为`@id/versionchecklib_failed_dialog_cancel`
350 |
351 | ```
352 | builder.setCustomDownloadFailedListener((context, versionBundle) -> {
353 | BaseDialog baseDialog = new BaseDialog(context, R.style.BaseDialog, R.layout.custom_download_failed_dialog);
354 | return baseDialog;
355 | });
356 | ```
357 | ***
358 |
359 | ### update Log
360 | - 2.2.1
361 | - 修复内存泄漏问题
362 | - 使用binder传递参数
363 | - 一些已知的bug
364 |
365 |
366 | ### 混淆配置
367 | ```
368 | -keepattributes *Annotation*
369 | -keepclassmembers class * {
370 | @org.greenrobot.eventbus.Subscribe ;
371 | }
372 | -keep enum org.greenrobot.eventbus.ThreadMode { *; }
373 |
374 | # Only required if you use AsyncExecutor
375 | -keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
376 | (java.lang.Throwable);
377 | }
378 | ```
379 |
380 |
381 | ### 最后
382 |
383 | ***
384 |
385 | - 更全面的使用请看 [demo](https://github.com/AlexLiuSheng/CheckVersionLib/blob/master/sample/src/main/java/com/allenliu/sample/v2/V2Activity.java)
386 |
387 | - 感谢各位对本库的支持
388 |
389 | - 欢迎star/issue
390 |
391 |
392 |
393 | ### License
394 |
395 | ***
396 |
397 | Apache 2.0
398 |
--------------------------------------------------------------------------------
/README_V1.1.md:
--------------------------------------------------------------------------------
1 | # CheckVersionLib[  ](https://bintray.com/zkxy/maven/VersionCheckLib/_latestVersion)
2 | 现在热更新技术挺火的,大公司都出了自己的热更新框架,但是各家热更新都有各自优缺点,终究不能解决所有bug,万不得已还是得进行版本升级,这是一个android上的自动版本检测并更新库。库集成了检测版本、下载版本以及自动安装升级
3 | ## 特点
4 | - [x] 任何地方都可以检测(可设置定时检测)
5 |
6 | - [x] app内任何地方都可以弹出升级对话框
7 |
8 | - [x] **自定义性强,手动回调解析,适用于各种版本检测接口**
9 |
10 | - [x] 自动处理下载和安装
11 |
12 | - [x] 自动请求读写权限
13 |
14 | - [x] **支持自定义界面**
15 |
16 | - [x] 支持强制更新
17 |
18 | ## 效果
19 |
20 |
21 |
22 |
23 |
24 | ## 使用步骤
25 | ### android studio导入
26 | `compile 'com.allenliu.versionchecklib:library:1.1'`
27 |
28 |
29 | ### 如何使用
30 | 1.自定义service,service继承 `AVersionService `,实现其中的 `onResponses(AVersionService service, String response)`抽象方法.
31 |
32 | 该方法主要是请求版本接口的回调,由于不同的使用者版本检测接口返回数据类型不一致,所以你需要自己解析数据,判断版本号之后调用升级对话框,如果使用库默认的界面直接调用如下方法: `service.showVersionDialog(downloadUrl,title,updateMsg )`
33 |
34 | 示例代码:
35 |
36 |
37 | if (serverVersion > clientVersion) {
38 | //传入下载地址,以及版本更新消息
39 | service.showVersionDialog(downloadUrl,title,updateMsg );}
40 |
41 |
42 |
43 |
44 |
45 | 2.在任意地方开启自定义service,并传入`VersionParam`
46 |
47 | versionParams = new VersionParams().setRequestUrl("http://www.baidu.com");
48 | Intent intent = new Intent(this, DemoService.class);
49 | intent.putExtra(AVersionService.VERSION_PARAMS_KEY, versionParams);
50 | startService(intent);
51 |
52 | `VersionParams`有如下方法,除了requestUrl都是可选值
53 |
54 |
55 |
56 | ### **自定义界面**
57 | 如果想自定义界面,只需创建一个继承自`VersionDialogActivity`的Activity,Activity设置Theme为透明:
58 |
59 | ` android:theme="@style/versionCheckLibvtransparentTheme"`
60 |
61 | 开启Service的时候,将自定义的Activity传入VersionParams
62 |
63 | `setCustomDownloadActivityClass(CustomVersionDialogActivity.class)`
64 |
65 | - 自定义 版本dialog,重写 `showVersionDialog()` ,在里面实现自己的逻辑,最后调用`downloadFile(url)`或者`downloadFile(url,filecallback)`注意不要调用父类的方法
66 |
67 | - 自定义 下载中dialog,重写`showLoadingDialog(int currentProgress)`,在里面实现自己的逻辑
68 |
69 | - 自定义 下载失败dialog ,重写`showFailDialog`,实现自己的逻辑
70 |
71 | - 强制更新。如果使用默认的版本dialog,`setCancelClickListner`回调里实现,具体用法请看demo
72 |
73 | - 除此之外还可以在定义的Activity里面监听一些下载和点击回调
74 |
75 | setOnDownloadSuccessListener(this);
76 |
77 | setCommitClickListener(this);
78 |
79 | setCancelClickListener(this);
80 |
81 | setOnDownloadingListener(this);
82 |
83 | ### 下载通知栏图标和文字替换
84 | 需要自定义图标只需在mimap文件下建立`ic_launcher`图标,替换标题只需在项目xml定义`app_name`属性,还有其他一些属性替换,如下表:
85 |
86 | | 属性名 | 属性值 |
87 | | ------------- |:-------------:|
88 | | versionchecklib_confirm | 确认 |
89 | | versionchecklib_cancel | 取消 |
90 | |versionchecklib_retry | 重试 |
91 | |versionchecklib_download_fail_retry| 下载失败是否重试? |
92 | |versionchecklib_download_finish | 下载完成,点击安装 |
93 | |versionchecklib_downloading | 正在下载中... |
94 | |versionchecklib_check_new_version |检测到新版本 |
95 | |versionchecklib_download_fail | 下载失败,点击重试|
96 | 更详细的使用请看demo
97 | `欢迎star和提issue`
98 | ## License
99 |
100 | Copyright 2017 AllenLiu.
101 |
102 | Licensed to the Apache Software Foundation (ASF) under one or more contributor
103 | license agreements. See the NOTICE file distributed with this work for
104 | additional information regarding copyright ownership. The ASF licenses this
105 | file to you under the Apache License, Version 2.0 (the "License"); you may not
106 | use this file except in compliance with the License. You may obtain a copy of
107 | the License at
108 |
109 | http://www.apache.org/licenses/LICENSE-2.0
110 |
111 | Unless required by applicable law or agreed to in writing, software
112 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
113 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
114 | License for the specific language governing permissions and limitations under
115 | the License.
116 |
117 |
--------------------------------------------------------------------------------
/README_V1.md:
--------------------------------------------------------------------------------
1 | # CheckVersionLib[  ](https://bintray.com/zkxy/maven/VersionCheckLib/_latestVersion)
2 |
3 | # [V2版来袭](https://github.com/AlexLiuSheng/CheckVersionLib/blob/master/README.MD)
4 | [English Doc](https://github.com/AlexLiuSheng/CheckVersionLib/blob/master/README_EN.md)
5 | ## 特点
6 | - [x] 任何地方都可以检测(可设置定时检测)
7 |
8 | - [x] app内任何地方都可以弹出升级对话框
9 |
10 | - [x] **自定义性强,手动回调解析,适用于各种版本检测接口**
11 |
12 | - [x] 自动处理下载和安装
13 |
14 | - [x] 自动请求读写权限
15 |
16 | - [x] **支持自定义界面**
17 |
18 | - [x] 支持强制更新
19 |
20 | - [x] 支持静默下载
21 |
22 | - [x] 使用okhttp请求,不与第三方请求框架冲突
23 |
24 | - [x] 适配到Android O
25 |
26 | ## 效果
27 |
28 |
29 |
30 |
31 |
32 | ## 使用步骤
33 | ### android studio导入
34 | `compile 'com.allenliu.versionchecklib:library:1.8.8'`
35 |
36 |
37 | ### 如何使用
38 | #### 1.请求版本接口 + 下载模块
39 | 1.自定义service,service继承 `AVersionService `,实现其中的 `onResponses(AVersionService service, String response)`抽象方法.
40 |
41 | 该方法主要是请求版本接口的回调,由于不同的使用者版本检测接口返回数据类型不一致,所以你需要自己解析数据,判断版本号之后调用升级对话框,如果使用库默认的界面直接调用如下方法: `service.showVersionDialog(downloadUrl,title,updateMsg )`
42 |
43 | 示例代码:
44 |
45 |
46 | if (serverVersion > clientVersion) {
47 | //传入下载地址,以及版本更新消息
48 | service.showVersionDialog(downloadUrl,title,updateMsg );
49 | // or
50 | service.showVersionDialog(downloadUrl,title,updateMsg,bundle);
51 | }
52 |
53 |
54 |
55 |
56 | 2.在任意地方开启自定义service,并传入`VersionParam`
57 |
58 | ```
59 | VersionParams.Builder builder = new VersionParams.Builder()
60 | .setRequestUrl("http://www.baidu.com")
61 | .setService(DemoService.class);
62 |
63 | AllenChecker.startVersionCheck(this, builder.build());
64 | ```
65 |
66 | #### 2.只使用下载模块
67 |
68 |
69 | 只使用下载模块不用定义第一步的service,正常传入versiongParams参数,不设置requestUrl和service,只用设置onlyDownload 为true。并且传入downloadUrl和需要显示的信息
70 |
71 |
72 | ```
73 | //如果仅使用下载功能,downloadUrl是必须的
74 | builder.setOnlyDownload(true)
75 | .setDownloadUrl("http://down1.uc.cn/down2/zxl107821.uc/miaokun1/UCBrowser_V11.5.8.945_android_pf145_bi800_(Build170627172528).apk")
76 | .setTitle("检测到新版本")
77 | .setUpdateMsg(getString(R.string.updatecontent));
78 |
79 | AllenChecker.startVersionCheck(this, builder.build());
80 | ```
81 |
82 | `VersionParams`属性见下表:
83 |
84 | | 属性名 | 是否必须 | 默认值 |解释|
85 | | ------------- |:-------------|:-------------|:-------------:|
86 | | requestUrl | 是 |-|请求版本接口的url|
87 | | service | 是 |-|指定你自己的service|
88 | |downloadAPKPath|否|/storage/emulated/0/AllenVersionPath/|apk下载路径|
89 | | httpHeaders | 否 |不传为空|http版本请求header|
90 | | pauseRequestTime | 否 |1000*30|版本接口请求失败与下次请求间隔时间(如果为-1表示请求失败不继续请求)|
91 | | httpHeaders | 否 |不传为空|http版本请求header|
92 | | requestMethod | 否 |GET|http版本请求方式|
93 | | requestParams | 否 |不传为空|http版本请求携带的参数|
94 | | customDownloadActivityClass | 否 |VersionDialogActivity.class|版本dialog Activity,使用默认界面不指定|
95 | | isForceRedownload | 否 |false|如果本地有缓存,是否强制重新下载apk(设置false会如果下载了安装包而用户没有安装则不会再次下载)|
96 | | isSilentDownload | 否 |false|静默下载开关|
97 | | onlyDownload |否|false|是否只使用下载模块|
98 | |title|否|null|只使用下载模块时,升级对话框的title|
99 | |updateMsg|否|null|只使用下载模块时,升级对话框内容|
100 | |downloadUrl|只使用下载模式时必须|-|只使用下载模块时传入的下载apk地址|
101 | |paramBundle|否|null|额外的一些参数可以放里面,可以在versiongDialogActivity里面使用|
102 | |isShowDownloadingDialog|否|true|是否显示下载对话框|
103 | |isShowNotification|否|true|是否显示下载的通知栏|
104 | |isShowDownloadFailDialog|否|true|是否显示下载失败对话框|
105 |
106 | #### 3.开启和关闭log
107 |
108 | `AllenChecker.init(true)`
109 |
110 | #### 4.取消请求
111 |
112 | 取消全部请求
113 |
114 | `AllenChecker.cancelMission();`
115 |
116 | ### **自定义界面**
117 | 如果想自定义界面,只需创建一个继承自`VersionDialogActivity`的Activity,
118 | Activity设置Theme为透明:
119 |
120 | ` android:theme="@style/versionCheckLibvtransparentTheme"`
121 |
122 | 设置launchMode为SingleTask
123 |
124 | ` android:launchMode="singleTask"`
125 |
126 | 记住将自定义的Activity传入VersionParams
127 |
128 | `setCustomDownloadActivityClass(CustomVersionDialogActivity.class)`
129 |
130 | - 调用父类`getVersionTitle()` ,`getVersionUpdateMsg()`,`getVersionParamBundle()`方法,这是从service传过来的值,可以在自定义界面使用
131 |
132 | - 自定义 `versionDialog`:
133 | 重写 `showVersionDialog()` ,在里面实现自己的逻辑,在确认按钮里调用 `super.dealAPK();`
134 |
135 |
136 | example code:
137 | ```
138 | versionDialog = new BaseDialog(this, R.style.BaseDialog, R.layout.custom_dialog_two_layout);
139 | TextView tvTitle = (TextView) versionDialog.findViewById(R.id.tv_title);
140 | TextView tvMsg = (TextView) versionDialog.findViewById(R.id.tv_msg);
141 | Button btnUpdate = (Button) versionDialog.findViewById(R.id.btn_update);
142 |
143 | versionDialog.show();
144 | //设置dismiss listener 用于强制更新,dimiss会回调dialogDismiss方法
145 | versionDialog.setOnDismissListener(this);
146 | //可以使用之前从service传过来的一些参数比如:title。msg,downloadurl,parambundle
147 | tvTitle.setText(getVersionTitle());
148 | tvMsg.setText(getVersionUpdateMsg());
149 | //可以使用之前service传过来的值
150 | Bundle bundle = getVersionParamBundle();
151 | btnUpdate.setOnClickListener(new View.OnClickListener() {
152 | @Override
153 | public void onClick(View view) {
154 | versionDialog.dismiss();
155 | CustomVersionDialogActivity.super.dealAPK();
156 |
157 | }
158 | });
159 | versionDialog.show();
160 | ```
161 |
162 | - 自定义 `downloadingDialog`,重写`showLoadingDialog(int currentProgress)`,在里面实现自己的逻辑
163 |
164 | - 自定义 `failDialog` ,重写`showFailDialog`,实现自己的逻辑
165 |
166 | - 强制更新。如果使用默认的版本dialog,`dialogDismiss`和`onDownloadSuccess`回调里关闭app,具体用法请看demo
167 |
168 | - 除此之外还可以在定义的Activity里面监听一些下载和点击回调
169 |
170 |
171 | setApkDownloadListener(this);
172 | setCommitClickListener(this);
173 | setDialogDimissListener(this);
174 |
175 | ### 强制更新
176 |
177 | 主要思路就是监听
178 |
179 | ```
180 | setApkDownloadListener(this);
181 | setDialogDimissListener(this);
182 | ```
183 |
184 |
185 | 具体查看[ForceUpdate](https://github.com/AlexLiuSheng/CheckVersionLib/tree/master/ForceUpdateDemo)
186 |
187 | ### 下载通知栏图标和文字替换
188 | 需要自定义图标只需在mimap文件下建立`ic_launcher`图标,替换标题只需在项目xml定义`app_name`属性,还有其他一些属性替换([仍然被替换?](https://github.com/AlexLiuSheng/CheckVersionLib/issues/83)),如下表:
189 |
190 | | 属性名 | 属性值 |
191 | | ------------- |:-------------:|
192 | | versionchecklib_confirm | 确认 |
193 | | versionchecklib_cancel | 取消 |
194 | |versionchecklib_retry | 重试 |
195 | |versionchecklib_download_fail_retry| 下载失败是否重试? |
196 | |versionchecklib_download_finish | 下载完成,点击安装 |
197 | |versionchecklib_downloading | 正在下载中... |
198 | |versionchecklib_check_new_version |检测到新版本 |
199 | |versionchecklib_download_fail | 下载失败,点击重试|
200 | 更详细的使用请看demo
201 | `欢迎star和提issue`
202 | ## 更新日志
203 | V 1.8.8
204 |
205 | - fix the oom of static context
206 |
207 | V 1.8.6
208 |
209 | - fix [issue80](https://github.com/AlexLiuSheng/CheckVersionLib/issues/80)
210 |
211 | V 1.8.4
212 | - support android 8
213 |
214 | V 1.8.3
215 | - fix [issue73](https://github.com/AlexLiuSheng/CheckVersionLib/issues/73)
216 | - fix [issue75](https://github.com/AlexLiuSheng/CheckVersionLib/issues/75)
217 |
218 | V 1.8.2
219 | - fix bug of silent downloading
220 |
221 | V 1.8.0
222 | - fix bugs of force update
223 | - fix [issue](https://github.com/AlexLiuSheng/CheckVersionLib/issues/68)
224 | - V1.7.7
225 | - fix [issue](https://github.com/AlexLiuSheng/CheckVersionLib/issues/64)
226 | - fix re downloading apk when app have cache of apk
227 | - fix [issue](https://github.com/AlexLiuSheng/CheckVersionLib/issues/63)
228 | - V1.7.6
229 | - support cancel all the task
230 | - V1.7.5
231 | - support multiple language mode
232 | - V1.7.4
233 | - solve [issues#59](https://github.com/AlexLiuSheng/CheckVersionLib/issues/59)
234 | - V1.7.2
235 | - support https request
236 | - V1.7.1
237 | - 增加是否显示下载通知栏开关
238 | - 增加是否显示下载对话框开关
239 | - V1.6.9
240 | - VersionDialogActivity statusbar transparent
241 | - V1.6.8
242 | - 增加只使用下载功能用法
243 | - V1.6.6
244 | - 解决[issues#33](https://github.com/AlexLiuSheng/CheckVersionLib/issues/33)
245 | - V1.6.5
246 | - 解决了[issues#32](https://github.com/AlexLiuSheng/CheckVersionLib/issues/32)
247 | - V1.6.0
248 | - 优化项目,移除okgo
249 | - 使用okhttp实现请求和下载
250 | - V1.5.4 [issues#27](https://github.com/AlexLiuSheng/CheckVersionLib/issues/27)
251 | - 解决了 [issues#27](https://github.com/AlexLiuSheng/CheckVersionLib/issues/27)
252 | - V1.5.3 [issues#26](https://github.com/AlexLiuSheng/CheckVersionLib/issues/26)
253 | - 解决了 [issues#26](https://github.com/AlexLiuSheng/CheckVersionLib/issues/26)
254 | - V1.5.2
255 | - 解决了 [issues#25](https://github.com/AlexLiuSheng/CheckVersionLib/issues/25)
256 | - V1.5.1
257 | - solve [issues#24](https://github.com/AlexLiuSheng/CheckVersionLib/issues/24)
258 | - V1.5
259 | - 增加getVersionTitle,getVersionParamBundle,getVersionUpdateMsg方法,方便自定义界面使用
260 | - 修复了对本地缓存apk的判断优化。只有本地安装包与当前app的包名一样并且versioncode不一样才会认为本地有apk
261 | - V1.4
262 | - 修复了之前自定义界面不能使用从service传过去的title,updateMsg问题
263 | - V1.3
264 | - 增加**静默下载**功能
265 | - 优化库启动方式
266 | - V1.2
267 | - **强制重新下载开关**功能
268 | - V1.1
269 | - 添加apk下载缓存,下载完成之后默认不再次下载。安装之后删除安装包
270 |
271 |
272 | ## License
273 |
274 | Copyright 2017 AllenLiu.
275 |
276 | Licensed to the Apache Software Foundation (ASF) under one or more contributor
277 | license agreements. See the NOTICE file distributed with this work for
278 | additional information regarding copyright ownership. The ASF licenses this
279 | file to you under the Apache License, Version 2.0 (the "License"); you may not
280 | use this file except in compliance with the License. You may obtain a copy of
281 | the License at
282 |
283 | http://www.apache.org/licenses/LICENSE-2.0
284 |
285 | Unless required by applicable law or agreed to in writing, software
286 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
287 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
288 | License for the specific language governing permissions and limitations under
289 | the License.
290 |
291 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = "1.8.0"
5 |
6 | repositories {
7 | mavenCentral()
8 | maven { url "https://jitpack.io" }
9 | google()
10 |
11 | }
12 | dependencies {
13 | classpath 'com.android.tools.build:gradle:8.0.2'
14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
15 |
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | mavenCentral()
22 | maven { url "https://jitpack.io" }
23 | google()
24 |
25 | }
26 | }
27 |
28 | task clean(type: Delete) {
29 | delete rootProject.buildDir
30 | }
31 |
--------------------------------------------------------------------------------
/gif/AllenVersionChecker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gif/AllenVersionChecker.png
--------------------------------------------------------------------------------
/gif/V2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gif/V2.gif
--------------------------------------------------------------------------------
/gif/custom.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gif/custom.gif
--------------------------------------------------------------------------------
/gif/main.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gif/main.jpg
--------------------------------------------------------------------------------
/gif/style1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gif/style1.png
--------------------------------------------------------------------------------
/gif/style2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gif/style2.png
--------------------------------------------------------------------------------
/gif/style3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gif/style3.png
--------------------------------------------------------------------------------
/gif/style4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gif/style4.png
--------------------------------------------------------------------------------
/gif/v2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gif/v2.jpg
--------------------------------------------------------------------------------
/gif/versionparams.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gif/versionparams.png
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Wed Apr 18 14:01:51 CST 2018
16 | android.defaults.buildfeatures.buildconfig=true
17 | android.enableJetifier=true
18 | android.nonFinalResIds=false
19 | android.nonTransitiveRClass=false
20 | android.useAndroidX=true
21 | org.gradle.jvmargs=-Xmx1536m
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Sep 24 17:24:55 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/library.jar
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | //apply plugin: 'kotlin-android-extensions'
4 | android {
5 | compileSdkVersion 32
6 | // buildToolsVersion "29.0.3"
7 | resourcePrefix "versionchecklib"
8 | defaultConfig {
9 | minSdkVersion 21
10 | targetSdkVersion 32
11 | }
12 |
13 | buildTypes {
14 |
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | namespace 'com.allenliu.versionchecklib'
21 | lint {
22 | abortOnError false
23 | }
24 | compileOptions {
25 | targetCompatibility JavaVersion.VERSION_17
26 | sourceCompatibility JavaVersion.VERSION_17
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(include: ['*.jar'], dir: 'libs')
32 | implementation 'androidx.appcompat:appcompat:1.5.1'
33 | implementation 'com.squareup.okhttp3:okhttp:4.10.0'
34 | implementation 'org.greenrobot:eventbus:3.3.1'
35 | implementation "androidx.annotation:annotation:1.6.0"
36 | }
37 |
--------------------------------------------------------------------------------
/library/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/CheckVersionLib/23ab03936b0bbd78c447ef8d4d10bfba4243e4cf/library/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/library/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/library/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/library/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | #Wed Feb 22 19:27:35 CST 2017
11 | sdk.dir=D\:\\androidsdk
12 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Eclipse\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
16 |
17 |
18 |
23 |
26 |
27 |
28 |
32 |
33 |
34 |
38 |
39 |
43 |
47 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/callback/APKDownloadListener.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.callback;
2 |
3 | import java.io.File;
4 |
5 | /**
6 | * Created by allenliu on 2017/8/16.
7 | */
8 |
9 | public interface APKDownloadListener {
10 | void onDownloading(int progress);
11 | void onDownloadSuccess(File file);
12 | void onDownloadFail();
13 | }
14 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/callback/CommitClickListener.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.callback;
2 |
3 | /**
4 | * Created by Allen Liu on 2017/2/23.
5 | */
6 |
7 | public interface CommitClickListener {
8 | void onCommitClick();
9 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/callback/DialogDismissListener.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.callback;
2 |
3 | import android.app.Dialog;
4 | import android.content.DialogInterface;
5 |
6 | /**
7 | * Created by Allen Liu on 2017/2/23.
8 | */
9 |
10 |
11 | public interface DialogDismissListener {
12 | void dialogDismiss(DialogInterface dialog);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/callback/DownloadListener.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.callback;
2 |
3 | import java.io.File;
4 |
5 | /**
6 | * Created by allenliu on 2017/8/16.
7 | */
8 |
9 | public interface DownloadListener {
10 | void onCheckerDownloading(int progress);
11 | void onCheckerDownloadSuccess(File file);
12 | void onCheckerDownloadFail();
13 | void onCheckerStartDownload();
14 | }
15 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/callback/OnCancelListener.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.callback;
2 |
3 | /**
4 | * Created by mac on 2018/5/14.
5 | */
6 |
7 | public interface OnCancelListener {
8 | void onCancel();
9 | }
10 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/core/JumpActivity.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.core;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.allenliu.versionchecklib.v2.eventbus.AllenEventType;
6 | import com.allenliu.versionchecklib.v2.eventbus.CommonEvent;
7 | import com.allenliu.versionchecklib.v2.ui.AllenBaseActivity;
8 |
9 | import org.greenrobot.eventbus.EventBus;
10 |
11 | /**
12 | * 不再库里做权限处理,默认下载路径为应用下载目录
13 | */
14 | public class JumpActivity extends AllenBaseActivity {
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | sendBroadcast(true);
20 | return;
21 | // Should we show an explanation?
22 | // Show an expanation to the user *asynchronously* -- don't block
23 | // this thread waiting for the user's response! After the user
24 | // sees the explanation, try again to request the permission.
25 | // if(!downloadUrl.isEmpty())
26 | // downloadAPK(downloadUrl,null);
27 | // No explanation needed, we can request the permission.
28 | // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
29 | // app-defined int constant. The callback method gets the
30 | // result of the request.
31 | }
32 |
33 | @Override
34 | public void showDefaultDialog() {
35 |
36 | }
37 |
38 | @Override
39 | public void showCustomDialog() {
40 |
41 | }
42 |
43 | private void sendBroadcast(boolean result) {
44 |
45 | //post event
46 | CommonEvent commonEvent = new CommonEvent();
47 | commonEvent.setEventType(AllenEventType.START_DOWNLOAD_APK);
48 | commonEvent.setSuccessful(true);
49 | commonEvent.setData(result);
50 | EventBus.getDefault().post(commonEvent);
51 |
52 | finish();
53 | }
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/core/VersionFileProvider.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.core;
2 |
3 | import androidx.core.content.FileProvider;
4 |
5 | /**
6 | * Created by Allen Liu on 2017/2/28.
7 | */
8 |
9 | public class VersionFileProvider extends FileProvider {
10 | }
11 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/core/http/AllenHttp.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.core.http;
2 |
3 |
4 | import android.os.Build;
5 |
6 | import com.allenliu.versionchecklib.utils.ALog;
7 | import com.allenliu.versionchecklib.v2.builder.RequestVersionBuilder;
8 |
9 | import org.json.JSONException;
10 | import org.json.JSONObject;
11 |
12 | import java.security.SecureRandom;
13 | import java.security.cert.CertificateException;
14 | import java.security.cert.X509Certificate;
15 | import java.util.Map;
16 | import java.util.concurrent.TimeUnit;
17 |
18 | import javax.net.ssl.HostnameVerifier;
19 | import javax.net.ssl.SSLContext;
20 | import javax.net.ssl.SSLSession;
21 | import javax.net.ssl.SSLSocketFactory;
22 | import javax.net.ssl.TrustManager;
23 | import javax.net.ssl.X509TrustManager;
24 |
25 | import okhttp3.FormBody;
26 | import okhttp3.MediaType;
27 | import okhttp3.OkHttpClient;
28 | import okhttp3.Request;
29 | import okhttp3.RequestBody;
30 |
31 | /**
32 | * Created by allenliu on 2017/8/31.
33 | */
34 |
35 | public class AllenHttp {
36 | private static OkHttpClient client;
37 |
38 | public static OkHttpClient getHttpClient() {
39 | if (client == null) {
40 | OkHttpClient.Builder builder = new OkHttpClient.Builder();
41 | builder.sslSocketFactory(createSSLSocketFactory(),new TrustAllCerts());
42 | builder.connectTimeout(15,TimeUnit.SECONDS);
43 | builder.hostnameVerifier(new TrustAllHostnameVerifier());
44 | client=builder.build();
45 | }
46 | return client;
47 | }
48 |
49 | private static class TrustAllHostnameVerifier implements HostnameVerifier {
50 | @Override
51 | public boolean verify(String hostname, SSLSession session) {
52 | return true;
53 | }
54 | }
55 |
56 | private static SSLSocketFactory createSSLSocketFactory() {
57 | SSLSocketFactory ssfFactory = null;
58 |
59 | try {
60 | SSLContext sc = SSLContext.getInstance("TLS");
61 | sc.init(null, new TrustManager[]{new TrustAllCerts()}, new SecureRandom());
62 |
63 | ssfFactory = sc.getSocketFactory();
64 | } catch (Exception e) {
65 | }
66 |
67 | return ssfFactory;
68 | }
69 |
70 | private static class TrustAllCerts implements X509TrustManager {
71 | @Override
72 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
73 | }
74 |
75 | @Override
76 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
77 | }
78 |
79 | @Override
80 | public X509Certificate[] getAcceptedIssuers() {
81 | return new X509Certificate[0];
82 | }
83 | }
84 |
85 |
86 | private static String assembleUrl(String url, HttpParams params) {
87 |
88 | StringBuffer urlBuilder = new StringBuffer(url);
89 | if (params != null) {
90 | urlBuilder.append("?");
91 | for (Map.Entry stringObjectEntry : params.entrySet()) {
92 | String key = stringObjectEntry.getKey();
93 | String value = stringObjectEntry.getValue() + "";
94 | urlBuilder.append(key).append("=").append(value).append("&");
95 | }
96 | url = urlBuilder.substring(0, urlBuilder.length() - 1);
97 | }
98 | ALog.e("url:" + url);
99 | return url;
100 | }
101 |
102 |
103 | private static String getRequestParamsJson(HttpParams params) {
104 | String json = null;
105 | if (params != null) {
106 | JSONObject jsonObject = new JSONObject();
107 | for (Map.Entry entry : params.entrySet()) {
108 | try {
109 | jsonObject.put(entry.getKey(), entry.getValue());
110 | } catch (JSONException e) {
111 | e.printStackTrace();
112 | }
113 | }
114 |
115 | json = jsonObject.toString();
116 | }
117 | ALog.e("json:" + json);
118 | return json;
119 | }
120 |
121 | /**********************************V2.0 Using RequestBuilder ************************************************************************/
122 |
123 | private static T assembleHeader(T builder, RequestVersionBuilder versionParams) {
124 | com.allenliu.versionchecklib.core.http.HttpHeaders headers = versionParams.getHttpHeaders();
125 | if (headers != null) {
126 | ALog.e("header:");
127 | for (Map.Entry stringStringEntry : headers.entrySet()) {
128 | String key = stringStringEntry.getKey();
129 | String value = stringStringEntry.getValue();
130 | ALog.e(key + "=" + value + "\n");
131 | builder.addHeader(key, value);
132 | }
133 | }
134 | return builder;
135 | }
136 | public static Request.Builder get(RequestVersionBuilder versionParams) {
137 | Request.Builder builder = new Request.Builder();
138 | assembleHeader(builder, versionParams);
139 | builder.url(assembleUrl(versionParams.getRequestUrl(), versionParams.getRequestParams()));
140 |
141 | return builder;
142 | }
143 |
144 | public static Request.Builder post(RequestVersionBuilder versionParams) {
145 | FormBody formBody = getRequestParams(versionParams);
146 | Request.Builder builder = new Request.Builder();
147 | assembleHeader(builder, versionParams);
148 | builder.post(formBody).url(versionParams.getRequestUrl());
149 | return builder;
150 | }
151 |
152 | public static Request.Builder postJson(RequestVersionBuilder versionParams) {
153 | MediaType JSON = MediaType.parse("application/json; charset=utf-8");
154 | String json = getRequestParamsJson(versionParams.getRequestParams());
155 | RequestBody body = RequestBody.create(JSON, json);
156 | Request.Builder builder = new Request.Builder();
157 | assembleHeader(builder, versionParams);
158 | builder.post(body).url(versionParams.getRequestUrl());
159 | return builder;
160 | }
161 |
162 | private static FormBody getRequestParams(RequestVersionBuilder versionParams) {
163 | FormBody.Builder builder = new FormBody.Builder();
164 | HttpParams params = versionParams.getRequestParams();
165 | //#https://github.com/AlexLiuSheng/CheckVersionLib/issues/293
166 | if(params!=null) {
167 | for (Map.Entry entry : params.entrySet()) {
168 | builder.add(entry.getKey(), entry.getValue() + "");
169 | ALog.e("params key:" + entry.getKey() + "-----value:" + entry.getValue());
170 | }
171 | }
172 | return builder.build();
173 | }
174 |
175 | }
176 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/core/http/FileCallBack.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.core.http;
2 |
3 |
4 | import android.os.Handler;
5 | import android.os.Looper;
6 |
7 | import com.allenliu.versionchecklib.utils.ALog;
8 |
9 | import java.io.File;
10 | import java.io.FileOutputStream;
11 | import java.io.IOException;
12 | import java.io.InputStream;
13 |
14 | import okhttp3.Call;
15 | import okhttp3.Callback;
16 | import okhttp3.Response;
17 |
18 | /**
19 | * Created by allenliu on 2017/8/31.
20 | */
21 |
22 | public abstract class FileCallBack implements Callback {
23 | private String path;
24 | private String name;
25 | private Handler handler;
26 |
27 | public FileCallBack(String path, String name) {
28 | this.path = path;
29 | this.name = name;
30 | handler = new Handler(Looper.getMainLooper());
31 | }
32 |
33 | @Override
34 | public void onFailure(Call call, IOException e) {
35 |
36 | handler.post(new Runnable() {
37 | @Override
38 | public void run() {
39 | onDownloadFailed();
40 | }
41 | });
42 |
43 | }
44 |
45 | @Override
46 | public void onResponse(final Call call, final Response response) {
47 | if(!response.isSuccessful()){
48 | handler.post(new Runnable() {
49 | @Override
50 | public void run() {
51 | onDownloadFailed();
52 |
53 | }
54 | });
55 | return;
56 | }
57 | InputStream is = null;
58 | byte[] buf = new byte[2048];
59 | int len = 0;
60 | FileOutputStream fos = null;
61 | // 储存下载文件的目录
62 | File pathFile = new File(path);
63 | if (!pathFile.exists()) {
64 | pathFile.mkdirs();
65 | }
66 |
67 | try {
68 | is = response.body().byteStream();
69 | long total;
70 | final File file = new File(path, name);
71 | if (file.exists()) {
72 | file.delete();
73 | } else {
74 | file.createNewFile();
75 | }
76 | fos = new FileOutputStream(file);
77 | long sum = 0;
78 | while ((len = is.read(buf)) != -1) {
79 | total = response.body().contentLength();
80 | // ALog.e("file total size:"+total);
81 | fos.write(buf, 0, len);
82 | sum += len;
83 | final int progress = (int) (((double) sum / total) * 100);
84 | // 下载中
85 | handler.post(new Runnable() {
86 | @Override
87 | public void run() {
88 | onDownloading(progress);
89 | }
90 | });
91 |
92 | }
93 | fos.flush();
94 | handler.post(new Runnable() {
95 | @Override
96 | public void run() {
97 | onSuccess(file, call, response);
98 |
99 | }
100 | });
101 |
102 | } catch (Exception e) {
103 | e.printStackTrace();
104 | handler.post(new Runnable() {
105 | @Override
106 | public void run() {
107 | onDownloadFailed();
108 |
109 | }
110 | });
111 | } finally {
112 | try {
113 | if (is != null)
114 | is.close();
115 | if (fos != null)
116 | fos.close();
117 | } catch (IOException e) {
118 | e.printStackTrace();
119 | }
120 | }
121 | }
122 |
123 |
124 | public abstract void onSuccess(File file, Call call, Response response);
125 |
126 | public abstract void onDownloading(int progress);
127 |
128 | public abstract void onDownloadFailed();
129 | }
130 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/core/http/HttpHeaders.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.core.http;
2 |
3 | import java.io.Serializable;
4 | import java.util.LinkedHashMap;
5 |
6 | /**
7 | * Created by allenliu on 2017/8/31.
8 | */
9 |
10 | public class HttpHeaders extends LinkedHashMap implements Serializable{
11 | }
12 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/core/http/HttpParams.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.core.http;
2 |
3 | import java.io.Serializable;
4 | import java.util.LinkedHashMap;
5 |
6 | public class HttpParams extends LinkedHashMapimplements Serializable {
7 |
8 |
9 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/core/http/HttpRequestMethod.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.core.http;
2 |
3 | /**
4 | * Created by Allen Liu on 2017/2/22.
5 | */
6 |
7 | public enum HttpRequestMethod {
8 | POST,GET, POSTJSON
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/utils/ALog.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.utils;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Created by allenliu on 2017/8/16.
7 | */
8 |
9 | public class ALog {
10 | private static final boolean debug = true;
11 |
12 | public static void e(String msg) {
13 | if (debug) {
14 | if (msg != null && !msg.isEmpty())
15 | Log.e("Allen Checker", msg);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/utils/AllenEventBusUtil.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.utils;
2 |
3 | import com.allenliu.versionchecklib.v2.eventbus.CommonEvent;
4 |
5 | import org.greenrobot.eventbus.EventBus;
6 |
7 | /**
8 | * Created by allenliu on 2018/1/18.
9 | */
10 |
11 | public class AllenEventBusUtil {
12 | public static void sendEventBus(int eventType) {
13 | CommonEvent commonEvent = new CommonEvent();
14 | commonEvent.setSuccessful(true);
15 | commonEvent.setEventType(eventType);
16 | EventBus.getDefault().post(commonEvent);
17 | }
18 | public static void sendEventBusStick(int eventType) {
19 | CommonEvent commonEvent = new CommonEvent();
20 | commonEvent.setSuccessful(true);
21 | commonEvent.setEventType(eventType);
22 | EventBus.getDefault().postSticky(commonEvent);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/versionchecklib/utils/AppUtils.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.versionchecklib.utils; /**
2 | * Copyright 2014 Zhenguo Jin
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *