From ad9d8259e60b2f39b078a2b5da42a79b37bf6f12 Mon Sep 17 00:00:00 2001 From: chenjuntao Date: Wed, 26 Sep 2018 11:40:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=9C=AC=E5=9C=B0=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E9=9D=9E=E6=8F=92=E4=BB=B6=E6=B8=B8=E6=88=8F=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=9C=89=E6=9B=B4=E6=96=B0=E7=9A=84=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E5=BE=85=E6=8E=A5=E5=8F=A3=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 ++ .../java/com/gh/common/util/PackageUtils.java | 52 ++++++++++++++++++- dependencies.gradle | 2 + 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 6474c50e72..fe53f15565 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -260,6 +260,9 @@ dependencies { implementation "com.scwang.smartrefresh:SmartRefreshLayout:${smartRefreshLayout}" implementation "net.cachapa.expandablelayout:expandablelayout:${expandableLayout}" + // 用于比较 versionName 是大于小于或等于 + implementation "com.g00fy2:versioncompare:${versioncompare}" + implementation "top.zibin:Luban:${luban}" implementation project(':libraries:gid') diff --git a/app/src/main/java/com/gh/common/util/PackageUtils.java b/app/src/main/java/com/gh/common/util/PackageUtils.java index 8bae4a99e0..676d3527bc 100644 --- a/app/src/main/java/com/gh/common/util/PackageUtils.java +++ b/app/src/main/java/com/gh/common/util/PackageUtils.java @@ -11,9 +11,12 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.support.v4.content.FileProvider; import android.text.TextUtils; +import com.g00fy2.versioncompare.Version; import com.gh.common.constant.Config; +import com.gh.gamecenter.BuildConfig; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.GameUpdateEntity; @@ -42,10 +45,14 @@ public class PackageUtils { List updateList = new ArrayList<>(); + boolean isAPluginGame = false; for (ApkEntity apkEntity : gameEntity.getApk()) { // 判断是否gh_version是否存在 String gh_version = (String) PackageUtils.getMetaData(context, apkEntity.getPackageName(), "gh_version"); if (gh_version != null && apkEntity.getGhVersion() != null) { + + // 确定这是一个插件游戏 + if (!isAPluginGame) isAPluginGame = true; gh_version = gh_version.substring(2); if (Long.parseLong(gh_version) < Long.parseLong(apkEntity.getGhVersion()) && apkEntity.getForce()) { GameUpdateEntity updateEntity = new GameUpdateEntity(); @@ -66,6 +73,41 @@ public class PackageUtils { } } + // 不是插件游戏 + if (!isAPluginGame) { + for (ApkEntity apkEntity : gameEntity.getApkNormal()) { + + String versionFromRequest = apkEntity.getVersion(); + String versionFromInstalledApp = getVersionByPackage(context, apkEntity.getPackageName()); + + // 是否需要显示更新 + boolean shouldShouldUpdate = apkEntity.getForce(); + + if (shouldShouldUpdate && !TextUtils.isEmpty(versionFromRequest) && !TextUtils.isEmpty(versionFromInstalledApp)) { + + // 根据版本判断是否需要更新 + shouldShouldUpdate = new Version(versionFromRequest).isHigherThan(versionFromInstalledApp); + + if (shouldShouldUpdate) { + GameUpdateEntity updateEntity = new GameUpdateEntity(); + updateEntity.setId(gameEntity.getId()); + updateEntity.setName(gameEntity.getName()); + updateEntity.setIcon(gameEntity.getIcon()); + updateEntity.setPackageName(apkEntity.getPackageName()); + updateEntity.setSize(apkEntity.getSize()); + updateEntity.setVersion(apkEntity.getVersion()); + updateEntity.setGhVersion(apkEntity.getGhVersion()); + updateEntity.setUrl(apkEntity.getUrl()); + updateEntity.setPlatform(apkEntity.getPlatform()); + updateEntity.setEtag(apkEntity.getEtag()); + updateEntity.setBrief(gameEntity.getBrief()); + updateEntity.setTag(gameEntity.getTag()); + updateList.add(updateEntity); + } + } + } + } + return updateList; } @@ -172,7 +214,15 @@ public class PackageUtils { if ("smartisan".equals(Build.MANUFACTURER)) { installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } - installIntent.setDataAndType(uri, "application/vnd.android.package-archive"); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, new File(path)); + installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + installIntent.setDataAndType(uri, "application/vnd.android.package-archive"); + installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + } else { + installIntent.setDataAndType(uri, "application/vnd.android.package-archive"); + } InstallUtils.getInstance(context).addInstall(getPackageNameByPath(context, path)); return installIntent; } diff --git a/dependencies.gradle b/dependencies.gradle index c9188ec61b..7e2ce309b2 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -64,4 +64,6 @@ ext { smartRefreshLayout = "1.1.0-alpha-7" luban = "1.1.7" + + versioncompare = "1.2.8" } \ No newline at end of file