我必须以编程方式检测谷歌应用程序和谷歌服务是否安装在设备上。
第一个解决方案是使用packagemanager:
private static final String GooglePlayStorePackageNameOld = "com.google.market";
private static final String GooglePlayStorePackageNameNew = "com.google.vending";
void someMethod() {
packageManager = getApplication().getPackageManager();
List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : packages) {
if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld) ||
packageInfo.packageName.equals(GooglePlayStorePackageNameNew)) {
googlePlayStoreInstalled = true;
break;
}
}
}
但是有更可靠的东西吗?
答案 0 :(得分:1)
我在测试市场意图的结果时找到了另一种方法
PackageManager pm = getPackageManager();
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=dummy"));
List<ResolveInfo> list = pm.queryIntentActivities(market, 0);
if (list != null && list.size() > 0)
mMarketInstalled = true;
else
mMarketInstalled = false;
您对此解决方案有何看法?