Goo
Goo

Reputation: 1328

How to detect whether google apps are installed or not on a android device

I have to detect programatically weither google apps and google services are installed on a device or not.

A first solution is to use the 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;
        }
    }
}

But is there something more reliable ?

Upvotes: 1

Views: 525

Answers (1)

Goo
Goo

Reputation: 1328

I find an other way in testing the result of a market intent

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;

What do you think about this solution ?

Upvotes: 1

Related Questions