CheckVersionLib
最新文档请看github
V2版震撼来袭,功能强大,链式编程,调用简单,集成轻松,扩展性强大
老规矩先看V2效果,这个版本最大的特点就是使用非常简单,相对于1.+版本
效果


特点
-
[x] 任何地方都可以调用
-
[x] 简单简单简单简单(重要的话我说四遍)
-
[x] 扩展性强大
-
[x] 所有具有升级功能的app均可使用,耶稣说的
-
[x] 更强大的自定义界面支持
-
[x] 支持强制更新(一行代码)
-
[x] 支持静默下载 (一行代码)
-
[x] 适配到Android O
导入
compile 'com.allenliu.versionchecklib:library:2.0.0'
使用
和1.+版本一样,两种模式
只使用下载模式
先来个最简单的调用
AllenVersionChecker
.getInstance()
.downloadOnly(
UIData.create().setDownloadUrl(downloadUrl)
)
.excuteMission(context);
UIData
:UIData是一个Bundle,用于存放用于UI展示的一些数据,后面自定义界面时候可以拿来用
请求服务器版本+下载
该模式最简单的使用
AllenVersionChecker
.getInstance()
.requestVersion()
.setRequestUrl(requestUrl)
.request(new RequestVersionListener() {
@Nullable
@Override
public UIData onRequestVersionSuccess(String result) {
//拿到服务器返回的数据,解析,拿到downloadUrl和一些其他的UI数据
...
return UIData.create().setDownloadUrl(downloadUrl);
}
@Override
public void onRequestVersionFailure(String message) {
}
})
.excuteMission(context);
请求版本一些其他的http参数可以设置,如下
AllenVersionChecker
.getInstance()
.requestVersion()
.setHttpHeaders(httpHeader)
.setRequestMethod(HttpRequestMethod.POSTJSON)
.setRequestParams(httpParam)
.setRequestUrl(requestUrl)
.request(new RequestVersionListener() {
@Nullable
@Override
public UIData onRequestVersionSuccess(String result) {
//拿到服务器返回的数据,解析,拿到downloadUrl和一些其他的UI数据
...
UIData uiData = UIData
.create()
.setDownloadUrl(downloadUrl)
.setTitle(updateTitle)
.setContent(updateContent);
//放一些其他的UI参数,拿到后面自定义界面使用
uiData.getVersionBundle().putString("key", "your value");
return uiData;
}
@Override
public void onRequestVersionFailure(String message) {
}
})
.excuteMission(context);
以上就是最基本的使用(库默认会有一套界面),如果还不满足项目需求,下面就可以用这个库来飙车了
一些其他的function设置
解释下,下面的builder叫DownloadBuilder
DownloadBuilder builder=AllenVersionChecker
.getInstance()
.downloadOnly();
or
DownloadBuilder builder=AllenVersionChecker
.getInstance()
.requestVersion()
.request()
取消任务
AllenVersionChecker.getInstance().cancelAllMission(this);
静默下载
builder.setSilentDownload(true); 默认false
强制更新
设置此listener即代表需要强制更新,会在用户想要取消下载的时候回调
需要你自己关闭所有界面
builder.setForceUpdateListener(() -> {
forceUpdate();
});
下载忽略本地缓存
如果本地有安装包缓存也会重新下载apk
builder.setForceRedownload(true); 默认false
是否显示下载对话框
builder.setShowDownloadingDialog(false); 默认true
是否显示通知栏
builder.setShowNotification(false); 默认true
自定义通知栏
builder.setNotificationBuilder(
NotificationBuilder.create()
.setRingtone(true)
.setIcon(R.mipmap.dialog4)
.setTicker("custom_ticker")
.setContentTitle("custom title")
.setContentText(getString(R.string.custom_content_text))
);
是否显示失败对话框
builder.setShowDownloadFailDialog(false); 默认true
自定义下载路径
builder.setDownloadAPKPath(address); 默认:/storage/emulated/0/AllenVersionPath/
可以设置下载监听
builder.setApkDownloadListener(new APKDownloadListener() {
@Override
public void onDownloading(int progress) {
}
@Override
public void onDownloadSuccess(File file) {
}
@Override
public void onDownloadFail() {
}
});
自定义界面
自定义界面使用回调方式,开发者需要返回自己定义的Dialog(父类android.app)
-
所有自定义的界面必须使用listener里面的context实例化
-
界面展示的数据通过UIData拿
自定义显示更新界面
设置CustomVersionDialogListener
-
定义此界面必须有一个确定下载的按钮,按钮id必须为
@id/versionchecklib_version_dialog_commit
-
如果有取消按钮(没有忽略本条要求),则按钮id必须为
@id/versionchecklib_version_dialog_cancel
eg.
builder.setCustomVersionDialogListener((context, versionBundle) -> {
BaseDialog baseDialog = new BaseDialog(context, R.style.BaseDialog, R.layout.custom_dialog_one_layout);
//versionBundle 就是UIData,之前开发者传入的,在这里可以拿出UI数据并展示
TextView textView = baseDialog.findViewById(R.id.tv_msg);
textView.setText(versionBundle.getContent());
return baseDialog;
});
自定义下载中对话框界面
设置CustomDownloadingDialogListener
- 如果此界面要设计取消操作(没有忽略),请务必将id设置为
@id/versionchecklib_loading_dialog_cancel
builder.setCustomDownloadingDialogListener(new CustomDownloadingDialogListener() {
@Override
public Dialog getCustomDownloadingDialog(Context context, int progress, UIData versionBundle) {
BaseDialog baseDialog = new BaseDialog(context, R.style.BaseDialog, R.layout.custom_download_layout);
return baseDialog;
}
//下载中会不断回调updateUI方法
@Override
public void updateUI(Dialog dialog, int progress, UIData versionBundle) {
TextView tvProgress = dialog.findViewById(R.id.tv_progress);
ProgressBar progressBar = dialog.findViewById(R.id.pb);
progressBar.setProgress(progress);
tvProgress.setText(getString(R.string.versionchecklib_progress, progress));
}
});
自定义下载失败对话框
设置CustomDownloadFailedListener
-
如果有重试按钮请将id设置为
@id/versionchecklib_failed_dialog_retry
-
如果有 确认/取消按钮请将id设置为
@id/versionchecklib_failed_dialog_cancel
builder.setCustomDownloadFailedListener((context, versionBundle) -> {
BaseDialog baseDialog = new BaseDialog(context, R.style.BaseDialog, R.layout.custom_download_failed_dialog);
return baseDialog;
});
最后
-
更全面的使用请看demo
-
感谢各位对本库的支持
-
欢迎star/issue
License
Apache 2.0
网友评论
builder.setCustomVersionDialogListener((context, versionBundle) -> {
@LayoutRes int dialogLayout = checkupDateModel.isForce() ? R.layout.custom_force_update_dialog_layout : R.layout.custom_update_dialog_layout;
BaseDialog baseDialog = new BaseDialog(context, R.style.BaseDialog, dialogLayout);
TextView tvMsg = baseDialog.findViewById(R.id.tv_msg);
TextView title = baseDialog.findViewById(R.id.tv_title);
TextView tvCancel = baseDialog.findViewById(R.id.versionchecklib_version_dialog_cancel);
tvMsg.setText(Html.fromHtml(checkupDateModel.getContent()));
title.setText(Html.fromHtml("检测到新版本: " + checkupDateModel.getVersionName()));
return baseDialog;
});
需要点击两次确定才能开始更新,请问是为什
Required by:
XiaoE:app:unspecified
XiaoE:app:unspecified > XiaoE:magicindicator:unspecified
这个怎么解决啊?
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.allenliu.versionchecklib.core.VersionParams.isSilentDownload()' on a null object reference
系统版本:8.0
库版本:1.8.6
问题:使用通知栏下载的时候,每一次更新下载进度都会有系统提示,会不停的有提示音和振动
java.lang.NoSuchMethodError: No direct method <init>(Landroid/content/Context;Ljava/lang/String;)V in class Landroid/support/v4/app/NotificationCompat$Builder; or its super classes (declaration of 'android.support.v4.app.NotificationCompat$Builder' appears in /data/app/com.hxe.hxeplatform-1/split_lib_dependencies_apk.apk)
at com.allenliu.versionchecklib.core.DownloadManager.createNotification(DownloadManager.java:230)
1.appname会被你的覆盖,具体原因不明
2.sample代码好乱,可以说稀烂
1.appname会被你的覆盖,具体原因不明
2.sample代码好乱,可以说稀烂
1,第一个是因为作者做了国际化,你没有,所以你新建个 values-zh,然后里面加入你的应用名称,例如我的:
<resources>
<string name="app_name">IT面试宝典</string>
</resources>
2,没有下载代码,不清楚,另外希望作者更新下通知栏上面,加入:
.setNotificationSmallIconRes(R.drawable.app_icon)//设置通知小图标
3,希望作者修改下通知栏下载进度条显示 20%/100%,有点不妥;
最后,感谢作者的付出。
系统版本:8.0
库版本:1.8.6
问题:使用通知栏下载的时候,每一次更新下载进度都会有系统提示,会不停的有提示音和振动
E/CustomVersionDialogActi: 正在下载中回调...
E/VersionDilaogActivity: -516096.0
E/CustomVersionDialogActi: 正在下载中回调...
E/VersionDilaogActivity: -537368.0
E/CustomVersionDialogActi: 正在下载中回调...
E/VersionDilaogActivity: -558584.0
E/CustomVersionDialogActi: 正在下载中回调...
E/VersionDilaogActivity: -577176.0
E/CustomVersionDialogActi: 正在下载中回调...
E/VersionDilaogActivity: -584120.0
E/CustomVersionDialogActi: 正在下载中回调...
E/VersionDilaogActivity: -603544.0
E/CustomVersionDialogActi: 正在下载中回调...
E/VersionDilaogActivity: -621528.0
E/CustomVersionDialogActi: 正在下载中回调...
E/VersionDilaogActivity: -630784.0
E/CustomVersionDialogActi: 正在下载中回调...
E/VersionDilaogActivity: -647168.0
E/CustomVersionDialogActi: 正在下载中回调...
E/VersionDilaogActivity: -666480.0
这是什么原因?
报内容提供者重名!!!
service.showVersionDialog(downloadUrl,title,updateMsg
这个service是哪来的 无力吐槽了..。。
allen debug liyu Key: 34359738368
7.0系统 报异常