如何检查Android设备是否安装了Google Play?

时间:2014-10-23 04:26:12

标签: android

我正在尝试检查设备是否在我的应用中安装了Google Play,但似乎无法做到这一点。我跟着帖子HERE但仍然无效,即使我正在使用模拟器进行测试,也总是返回true,它安装了com.android.vending。所以我检查错误的包名?有什么想法吗?

提前致谢!

2 个答案:

答案 0 :(得分:1)

按照Dcoumentation检查设备是否提供Google Play服务。

总之,简单地说:

// Getting status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

// Showing status
if(status==ConnectionResult.SUCCESS)
//Google Play Services are available
else{
//Google Play Services are not available
}

希望这会对你有所帮助:)。

答案 1 :(得分:1)

最后,找到了一种检查Google Play的方法,这里是代码:

public static boolean isPackageInstalled(Context context) {
    PackageManager pm = context.getPackageManager();
    boolean app_installed = false;
    try {
       PackageInfo info = pm.getPackageInfo("com.android.vending", PackageManager.GET_ACTIVITIES);
       String label = (String) info.applicationInfo.loadLabel(pm);
       app_installed = (!TextUtils.isEmpty(label) && label.startsWith("Google Play"));
    } catch(PackageManager.NameNotFoundException e) {
       app_installed = false;
    }
    return app_installed;
}
相关问题