Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android license check going straight to applicationError(...)

I just implemented the android server check in my app. I am using the StrictPolicy method because I may be just a little bitter from the pirated version have 5X the amount of downloads as the version in the market... Anyway, I coded the method basically verbatim into my source code. However, when I toggle the License Test Response on the developer console to Licensed, I get the unlicensed dialog. However, in the applicationError method, dontAllow() is called and when i comment this line out, the unlicensed dialog does not show. What am I doing wrong? Here is my MyLicenseCheckerCallback class.

I call doCheck in the onCreate, and again in the onResume.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHandler = new Handler();
    mLicenseCheckerCallback = new MyLicenseCheckerCallback();

    // Construct the LicenseChecker with a Policy.
    mChecker = new LicenseChecker(
        this, new ServerManagedPolicy(this,
            new AESObfuscator(SALT, getPackageName(), deviceId)),
            BASE64_PUBLIC_KEY
            );
    doCheck();

    setContentView(R.layout.main);
    ...


private void doCheck() {
    mChecker.checkAccess(mLicenseCheckerCallback);
}

private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
    public void allow() {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        // Should allow user access.
    }

    public void dontAllow() {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        //Be as annoying as possible
        illegalDownload = new IllegalDownloadHandler(speedy.this);
        illegalDownload.show();
        illegalDownload.setOnDismissListener(new OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    Intent goToMarket = null;
                    goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.TimothyMilla.SpeedBoost"));
                    startActivity(goToMarket);
                    illegalDownload.dismiss();
                }
        });
        // Should not allow access. An app can handle as needed,
        // typically by informing the user that the app is not licensed
        // and then shutting down the app or limiting the user to a
        // restricted set of features.
        // In this example, we show a dialog that takes the user to Market.
        //showDialog(0);
        //onDestroy();
    }

    @Override
    public void applicationError(ApplicationErrorCode errorCode) {
        // TODO Auto-generated method stub
        dontAllow();
        //when I comment the above line out, the unlicensed dialog is not shown.
    }

    private void displayResult(final String result) {
        mHandler.post(new Runnable() {
            public void run() {
                //dontAllow();
                Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
                //setProgressBarIndeterminateVisibility(false);
            }
        });
    }
}
like image 814
Timothy Miller Avatar asked Feb 24 '23 15:02

Timothy Miller


1 Answers

Since you didn't update my comment, my guesses... make sure you:

1- copied your public key correctly.

2- populated deviceId, as I think you are. Just making sure because your code above is hiding that declaration. But since it would throw compile errors at you, I'm sure you are.

3- changed the response code in the developer console (you said you have).

4- Finally, that you included the proper permissions in the Android manifest file:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
like image 175
davidcesarino Avatar answered Mar 08 '23 13:03

davidcesarino