Android: how to verify package is genuine

1.6k Views Asked by At

In one of my apps, I would like to detect if the user has got another app of mine installed.

This code works:

    PackageManager pm = mAppContext.getPackageManager();
    try {
        pm.getPackageInfo("com.example.packagename", PackageManager.GET_ACTIVITIES);
        // do something
    } catch (PackageManager.NameNotFoundException e) {
        // nothing to do
    }

But I wonder how I can verify that the user has genuinely downloaded the app from Google Play. I guess it would be possible to install a non genuine package with the same package name, right?

1

There are 1 best solutions below

7
On BEST ANSWER

PackageManager has a method getInstallerPackageName that for given package name gives you name of the installer. For pre-loaded(unless they are not installed from other 'market' like SamsungApps) and self-installed applications will return null. For applications originating from Google Play you should get com.android.vending. And I don't think that you are able to install two applications with the same package names declared in the manifest.