Cannot determine whether Google play store is installed or not on Android device(无法确定 Android 设备上是否安装了 Google Play 商店)
问题描述
这是检查设备上已安装软件包的简单问题...在我将操作系统升级到 2.3.5 之前,我可以使用以下代码找到 Market/Play 商店:
This was a simple matter of checking the installed packages on the device... before I've upgraded my OS to 2.3.5, I could locate the Market/Play store, using this code:
private static final String GooglePlayStorePackageName = "com.google.market";
void someMethod() {
packageManager = getApplication().getPackageManager();
List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : packages) {
if (packageInfo.packageName.equals(GooglePlayStorePackageName)) {
googlePlayStoreInstalled = true;
break;
}
}
}
更新后由于某种原因,我根本找不到表明应用程序已安装的to包名称,虽然它在设备上,我可以访问市场.
For some reason after the update, I simply cannot find the to package name to indicate the application is installed, although it is on the device, and I can access the market.
包名有变化吗?还是我看错了?
Has the package name changed? or perhaps I'm looking at this the wrong way?
谢谢,
亚当.
更新:
这是一种检查是否安装了软件包的愚蠢方法……更好的方法是:
That was a stupid way to check if a package is installed... a better way is:
protected final boolean isPackageInstalled(String packageName) {
try {
application.getPackageManager().getPackageInfo(packageName, 0);
} catch (NameNotFoundException e) {
return false;
}
return true;
}
推荐答案
请注意,这近 5 年的旧代码并不是最优的,Google 不喜欢无缘无故检查所有已安装的软件包.请同时查看其他答案.
包名已更改,现在是 com.android.vending
The package name has changed, it is now com.android.vending
试试:
private static final String GooglePlayStorePackageNameOld = "com.google.market";
private static final String GooglePlayStorePackageNameNew = "com.android.vending";
void someMethod() {
PackageManager 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;
}
}
}
这篇关于无法确定 Android 设备上是否安装了 Google Play 商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法确定 Android 设备上是否安装了 Google Play 商店
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01