参考:https://github.com/AlexLiuSheng/CheckVersionLib
image.png
val parm = HttpParams()
parm.put("type", "android");
parm.put("versionCode", APKVersionInfoUtils.getVersionCode(me)); //APKVersionInfoUtils.getVersionCode(me) 12
var builder = AllenVersionChecker
.getInstance()
.requestVersion()
.setRequestMethod(HttpRequestMethod.POSTJSON)
.setRequestParams(parm)
.setRequestUrl(Constant.TEST_URL + "/" + Constant.VERSION)
.request(object : RequestVersionListener {
override fun onRequestVersionSuccess(
downloadBuilder: DownloadBuilder?, result: String?
): UIData? {
val data = JSON.parseObject(result, UpdateData::class.java)
if (data.status == 200) {
if (data.data.versionCode > APKVersionInfoUtils.getVersionCode(me)) {
Log.e("打印下载路径","获得结果->" + result)
return UIData.create()
.setDownloadUrl(data.data.downloadUrl)
.setTitle("版本升级")
.setContent(data.data.versionInfo)
}
return null
}
return null
}
override fun onRequestVersionFailure(message: String?) {
ToastUtils.showShort("更新请求失败")
Log.e("测试更新apk","更新请求失败" + message)
}
})
//设置自定义布局
builder.setCustomVersionDialogListener(object : CustomVersionDialogListener{
override fun getCustomVersionDialog(context: Context?, versionBundle: UIData?): Dialog {
var baseDialog = BaseDialog(context)
baseDialog.setContentView(R.layout.dialog_update)
var tvContent = baseDialog.findViewById<TextView>(R.id.tv_content)
var tvTitle = baseDialog.findViewById<TextView>(R.id.tv_title)
tvContent?.text = versionBundle?.content
tvTitle?.text = versionBundle?.title
return baseDialog
}
})
builder.executeMission(me)
网友评论