Question

I'm trying to implement the LVL (Licensing Verification Library for Android), but running into a problem when the license check fails. I pop up a Dialog which explains that the license check failed and presents them with two buttons. One button is "Retry" which I want to immediately do another check or "Purchase App" which redirects them to buy the app on the App Market.

When I tap the Retry button, I can see from logging messages that my licensing check is called, I receive another "dont allow" callback and I try to show the above failure dialog again (I see onPrepareDialog() get called again).

The problem is the second dialog doesn't actually show. So the user can use the app even though the license check failed. Why isn't the dialog popping up again and again?

I believe this is all of the relevant code:

private void checkLicense() {
    Log.d(TAG, "Checking License...");
    this.licenseChecker.checkAccess(this.licenseCheckerCallback);
}

private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
    public void allow() { }

    public void dontAllow() {
        Log.d(TAG, "License resposne: Don't Allow");
        if (isFinishing())
            return; // Don't update UI if Activity is finishing.
        // Should not allow access. In most cases, the app should assume
        // the user has access unless it encounters this. If it does,
        // the app should inform the user of their unlicensed ways
        // and then either shut down the app or limit the user to a
        // restricted set of features.
        // In this example, we show a dialog that takes the user to Market.
        Log.d(TAG, "Showing No License Dialog");
        showDialog(DIALOG_NO_LICENSE_ID);
    }

    public void applicationError(ApplicationErrorCode errorCode) {
        if (isFinishing())
            return; // Don't update UI if Activity is finishing.
        // This is a polite way of saying the developer made a mistake
        // while setting up or calling the license checker library.
        showDialog(DIALOG_APPLICATION_ERROR_ID);
    }
}

protected Dialog onCreateDialog(int id) {
    Log.d(TAG, "Creating Dialog "+id);
    switch(id) {
    case DIALOG_NO_LICENSE_ID:
        return this.makeRetryPurchaseDialog(getString(R.string.no_license));
    case DIALOG_APPLICATION_ERROR_ID:
        return this.makeRetryPurchaseDialog(this.applicationErrorMessageForDialog);
    }
    return null;
}

private Dialog makeRetryPurchaseDialog(String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(CalculatorTabActivity.this);
    builder.setMessage(message).setCancelable(false)
    .setPositiveButton("Retry", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            CalculatorTabActivity.this.checkLicense();
        }
    }).setNegativeButton("Purchase App", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            CalculatorTabActivity.this.openAppMarket();
        }
    });
    return builder.create();
}
Was it helpful?

Solution

Just as an idea, try to explicitly call for dialog dismissing:

...
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        dissmissDialog(DIALOG_NO_LICENSE_ID);
        CalculatorTabActivity.this.checkLicense();
    }
})

Also, if that will not work, try using removeDialog(DIALOG_NO_LICENSE_ID) instead of dissmissDialog(DIALOG_NO_LICENSE_ID).

Finally what code (if at all) do you have in onPrepareDialog() ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top