gpt4 book ai didi

android - 如何从我的 Android 应用程序检测已安装的 Chrome 版本?

转载 作者:太空宇宙 更新时间:2023-11-03 13:08:28 27 4
gpt4 key购买 nike

我正在开发一项功能,仅当设备上安装的 chrome 版本高于 65 版时,我才需要将用户从 Android Native APP 转换到 Chrome 自定义选项卡。所以我的问题是,有没有一种方法可以检测到 chrome来自 Android Native App 的版本?

最佳答案

private boolean isChromeInstalledAndVersionGreaterThan65() {
PackageInfo pInfo;
try {
pInfo = getPackageManager().getPackageInfo("com.android.chrome", 0);
} catch (PackageManager.NameNotFoundException e) {
//chrome is not installed on the device
return false;
}
if (pInfo != null) {
//Chrome has versions like 68.0.3440.91, we need to find the major version
//using the first dot we find in the string
int firstDotIndex = pInfo.versionName.indexOf(".");
//take only the number before the first dot excluding the dot itself
String majorVersion = pInfo.versionName.substring(0, firstDotIndex);
return Integer.parseInt(majorVersion) > 65;
}
return false;
}

Obviously this will work until Chrome will be versioned how they did until now, if they will decide to change the versioning the logic should be updated as well. (I don't think this will happen but for max safety put everything in a try-catch)

关于android - 如何从我的 Android 应用程序检测已安装的 Chrome 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51733237/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com