优化下载服务中检测apk完整性时顺便同步检查版本号是否和当前吧版本号一致,如果一致认为就是最新包不再重复安装

This commit is contained in:
zlzw 2024-11-13 10:53:36 +08:00
parent cfb9cca71a
commit 589e855aba

View File

@ -188,8 +188,10 @@ public class DownloadService extends Service {
if (downloadFile == null || !downloadFile.exists()) return false; if (downloadFile == null || !downloadFile.exists()) return false;
try { try {
PackageManager pm = mContext.getPackageManager(); PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), Context.MODE_PRIVATE);
PackageInfo info = pm.getPackageArchiveInfo(downloadFile.getAbsolutePath(), PackageManager.GET_ACTIVITIES); PackageInfo info = pm.getPackageArchiveInfo(downloadFile.getAbsolutePath(), PackageManager.GET_ACTIVITIES);
if (info == null) return false; if (info == null) return false;
if(info.versionCode == packageInfo.versionCode) return false;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }