0

I've made an app which has pro features locked and you must buy the pro version key unlocker on play store to unlock them. Also, the main free app is not available on play store. Actually I've made a Boolean to check if the unlocker app with the package name stated in PACKAGE_NAME was downloaded from play store.

The problem is that this Boolean always returns false and so also if I've bought the pro key unlocker apk on play store, it always prompts that the app is not genuine. Can anyone tell me why?

Here is the Boolean code:

    public boolean isValid() {
    PackageManager pm = this.getPackageManager();
    String installPM = pm.getInstallerPackageName(PACKAGE_NAME);

    if ( installPM == null ) {
        // Definitely not installed from Android Market
        return false;
    }
    else if ( installPM.equals("com.google.android.feedback") ) {
        // Installed from the Android Market
        return true;
    }

    return false;
}

Here is the if statement checker:

if(isPro()) {

        if (!isValid()) {
            Log.d(TAG, "This is an hack!");
            isHacked();
        }
    }

Edit: As stated in comments, for me the problem is that PackageManager pm = this.getPackageManager();refers to the main free app (which contains the activity where I'm using this Boolean) and not at the external application unlocker which has another package name of course. So as the free app is not available on play store it always returns null... but how can I make PackageManager pm = this.getPackageManager(); to refer at another package name?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
androidexpert35
  • 319
  • 1
  • 10
  • have you debugged it? what's the value of the installPM variable? maybe installPM is null? – RetteMich May 19 '17 at 12:36
  • or maybe not null but a case sensitive package name – ΦXocę 웃 Пepeúpa ツ May 19 '17 at 12:39
  • Yes please first debug and see what's it. See [getInstallerPackageName returns null](http://stackoverflow.com/a/13676757/5818889). According to that anwser I'm afraid it's null indeed. – glee8e May 19 '17 at 12:39
  • `return "com.google.etc".equals(installPM);` is a more concise way to write this conditional logic. – Andy Turner May 19 '17 at 12:40
  • for me the problem is that PackageManager pm = this.getPackageManager(); referes to the free app and not to the Pro app key. so as the free app is not available on play store it always returns null... but how can i fix this? – androidexpert35 May 19 '17 at 12:49

1 Answers1

0

Those are the expected return values of package manager:

  • null - developer
  • com.android.vending - google play
  • com.amazon.venezia - amazon app
  • com.sec.android.app.samsungapps - Samsung app store

but as @nickthefreak said, you should debug it or print the value of installPM

Community
  • 1
  • 1
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216