如何检测Google Play是否已安装? (不市场) [英] How to detect if Google Play is installed? (Not Market)

查看:988
本文介绍了如何检测Google Play是否已安装? (不市场)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装的应用程序是否被称为Google Play或Market,包名称与 com.android.vending 相同。

Whether the app installed is called Google Play or Market, the package name is the same com.android.vending.

我需要检测应用程序是否为Google Play或Market,我检查了PackageInfo,除了 versionCode 版本号可以提供帮助。

I need to be able to detect whether the app is Google Play or Market, I've checked in PackageInfo and nothing except versionCode and versionName can be of help.

有谁知道第一个 versionCode 是或 versionName 用于Google Play应用程序?

Does anyone know what the first versionCode was or versionName was for Google Play app?

如果有人知道任何其他检测方式, p>

If anyone knows any other way of detecting this let me know.

推荐答案

我想出了如何检查应用程序标签。我使用调试器来查看 packageInfo 中返回的内容,这就是为什么我最初没有看到它的原因。

I figured out how to check the application label. I was using the debugger to see what all was being returned in packageInfo that's why I didn't see it initially.

public static boolean isGooglePlayInstalled(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 = (label != null && !label.equals("Market"));
    }
    catch (PackageManager.NameNotFoundException e)
    {
           app_installed = false;
    }
    return app_installed;
}

这篇关于如何检测Google Play是否已安装? (不市场)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆