fix: 荣耀安卓14手机安装游戏跳转至浏览器 https://jira.shanqu.cc/browse/GHZSCY-6588
This commit is contained in:
@ -4,6 +4,7 @@ import android.app.Activity
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@ -15,7 +16,6 @@ import com.gh.download.server.BrowserInstallHelper
|
||||
import com.gh.gamecenter.BuildConfig
|
||||
import com.gh.gamecenter.common.constant.Constants
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.core.utils.CurrentActivityHolder
|
||||
import com.gh.gamecenter.core.utils.MD5Utils
|
||||
import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.install.InstallService
|
||||
@ -31,6 +31,15 @@ object PackageInstaller {
|
||||
|
||||
private val listeners = mutableListOf<OnInstallListener>()
|
||||
|
||||
private val packageInstallerPackageName = arrayOf(
|
||||
"com.android.packageinstaller",
|
||||
"com.miui.packageinstaller",
|
||||
"com.google.android.packageinstaller",
|
||||
"com.samsung.android.packageinstaller",
|
||||
"com.lenovo",
|
||||
"com.zhuoyi"
|
||||
)
|
||||
|
||||
/**
|
||||
* 为了兼容java代码
|
||||
*/
|
||||
@ -274,11 +283,27 @@ object PackageInstaller {
|
||||
}
|
||||
installIntent.setDataAndType(uri, "application/vnd.android.package-archive")
|
||||
}
|
||||
|
||||
updateSystemInstallerIfAvailable(context, installIntent)
|
||||
|
||||
InstallUtils.getInstance()
|
||||
.addInstall(PackageUtils.getPackageNameByPath(context, path))
|
||||
return installIntent
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找并设置系统安装器作为安装 intent 的包名
|
||||
*/
|
||||
private fun updateSystemInstallerIfAvailable(context: Context, intent: Intent) {
|
||||
for (rf in context.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)) {
|
||||
val targetPackageName = packageInstallerPackageName.firstOrNull { rf.activityInfo.packageName.contains(it) }
|
||||
if (!targetPackageName.isNullOrEmpty()) {
|
||||
intent.setPackage(targetPackageName)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 卸载应用
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user