Android app检测更新功能
来源:互联网 发布:微单和单反的区别知乎 编辑:程序博客网 时间:2024/05/16 06:02
话不多说, 直接上核心代码
//检查更新, 返回接口数据HttpConfig.apiVersionVcheckedTask(new TaskCallBack() { @Override public void onPostExecute(String string) { //将接口返回来的json解析为model HttpResult<Version> result = JsonUtil.jsonToModel(string, new TypeReference<HttpResult<Version>>(){}); //检查返回的结果是否有效 if (!HttpConfig.isValid(result) || result.getPayload() == null) { return; } //版本Model final Version version = result.getPayload(); //本地获取版本号 int oldCode = VersionUtil.getVersionCode(activity); //接口返回的版本号 String versionCode = version.getVersionCode(); int newCode; try { newCode = Integer.parseInt(versionCode); }catch (Exception ex){ newCode = 0; } //将远程服务器中的版本号与本地版本号进行比较 if (newCode >= 0 && oldCode >= 0 && newCode > oldCode) { LogUtil.println("有新版本"); //app下载地址不为空, 继续下面的操作 if (!StringUtil.isEmpty(version.getPath())) { //TODO //我这里是直接跳转到网页去下载app, 你也可以在点击按钮后才跳转 LogUtil.println("开始下载apk:" + version.getPath()); Uri uri = Uri.parse(version.getPath()); Intent intent = new Intent(Intent.ACTION_VIEW, uri); activity.startActivity(intent); } return; } LogUtil.println("已经最新版本"); }});
/** * 获取apk本地版本号 * @param context * @return */public static int getVersionCode(Context context) { try { PackageInfo pi=context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pi.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return 0; }}
0 0
- Android app检测更新功能
- Android App更新功能
- Android APP功能测试检测点总结
- iOS App的版本检测更新功能(最新版)
- iOS日常需求:iOS app实现检测更新功能
- android APP检测版本更新以及后台服务更新
- android APP检测版本更新以及后台服务更新
- Android开发笔记--检查更新app功能
- Android 开发中 app版本更新功能
- App检测更新
- APP实现检测更新
- app检测更新
- 检测App更新
- iOS App检测更新
- 检测App更新
- App检测更新
- 【iOS】APP实现检测更新
- App检测版本更新 iOS
- NOYJ83——迷宫寻宝(二) 计算几何
- 内网外网
- JAVA多线程:线程同步
- Objective-C self和super关键字解析
- 【小练习06】HTML+CSS--电影公告
- Android app检测更新功能
- Git恢复被修改的文件--已提交到远程仓库
- 机器学习实战——python实现k-means聚类算法
- 测试代码中的“{}”是否匹配
- Qt模拟键盘按键与组合键
- hibernate--环境搭建(Maven)
- 大数据技术-HBase:MSLAB介绍
- Vue学习之路
- Pandas如何将Series的复合索引提取为列?