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;
}
2条答案
按热度按时间50pmv0ei1#
字符串
显然,这将工作,直到Chrome将版本如何,他们到现在为止,如果他们将决定改变版本的逻辑应该更新以及。(我不认为这将发生,但最大的安全把一切都在一个尝试捕捉)
如果目标是API 30或以上,请不要忘记将Chrome软件包添加到您想要在
AndroidManifest.xml
中查询的软件包列表中:型
cgvd09ve2#
字符串
然后调用上面的方法,
型