🔥原生DownloadManager实现版本的检测更新,完美适配Android M/N/O/P/Q,兼容AndroidX
原生DownloadManager实现版本的检测更新,可采取静默模式,非静默模式(进度框),是否强制更新、是否MD5校验、完美适配Android M/N/O/P/Q
allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}
dependencies {
implementation 'com.github.NewHuLe:AppUpdate:v1.7'
}
AppUpdate appUpdate = new AppUpdate.Builder()
//更新地址(必须)
.newVersionUrl("https://imtt.dd.qq.com/16891/8EC4E86B648D57FDF114AF5D3002C09B.apk")
// 版本号(非必须)
.newVersionCode("v1.7")
// 文件大小(非必须)
.fileSize("5.8M")
// 更新内容(非必填,默认“1.用户体验优化\n2.部分问题修复”)
.updateInfo("1.用户体验优化\n2.部分问题修复")
.build();
new UpdateManager().startUpdate(MainActivity.this, appUpdate);
// 更新的数据参数
AppUpdate appUpdate = new AppUpdate.Builder()
//更新地址(必传)
.newVersionUrl("https://imtt.dd.qq.com/16891/apk/5CACCB57E3F02E46404D27ABAA85474C.apk")
// 版本号(非必填)
.newVersionCode("v1.6")
//【建议】:自定义布局在静默下载模式下使用
// 通过传入资源id来自定义更新对话框,注意取消更新的id要定义为btnUpdateLater,立即更新的id要定义为btnUpdateNow(非必填)
.updateResourceId(R.layout.dialog_update)
// 更新的标题,弹框的标题(非必填,默认为应用更新)
.updateTitle(R.string.update_title)
// 更新内容的提示语,内容的标题(非必填,默认为更新内容)
.updateContentTitle(R.string.update_content_lb)
// 更新内容(非必填,默认“1.用户体验优化\n2.部分问题修复”)
.updateInfo("1.用户体验优化\n2.部分问题修复")
// 文件大小(非必填)
.fileSize("5.8M")
// 保存文件路径(默认前缀:Android/data/包名/files/ 文件名:download)
.savePath("/A/B")
//是否采取静默下载模式(非必填,只显示更新提示,后台下载完自动弹出安装界面),否则,显示下载进度,显示下载失败
.isSilentMode(false)
//是否强制更新(非必填,默认不采取强制更新,否则,不更新无法使用)
.forceUpdate(0)
//文件的MD5值,默认不传,如果不传,不会去验证md5(非静默下载模式生效,若有值,且验证不一致,会启动浏览器去下载)
.md5("2d9feb595d3aa093e9ee49412d2c8805")
.build();
new UpdateManager().startUpdate(MainActivity.this, appUpdate);
Copyright 2019 胡乐
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.