0

I'm implementing licensing in my Android App.

Why does LicenseCheckerCallback's method allow should return RETRY and NOT_LICENSED and dontAllow RETRY and LICENSED?

Accordingly to their method's name they shouldn't return nothing than respectively LICENSED and NOT_LICENSED/RETRY.

I must know how to properly handle the returned code in order to know if the user did download my App from Google Play.

The piece of script that return the code (int policyReason) is this:

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

    public void dontAllow(int policyReason) {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        displayResult(getString(R.string.dont_allow));
        // 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 a deep
        // link returned by the license checker.
        // If the reason for the lack of license is that the service is
        // unavailable or there is another problem, we display a
        // retry button on the dialog and a different message.
        displayDialog(policyReason == Policy.RETRY);
    }

    ...
}

The LicenseCheckerCallback official documentation says:

public interface LicenseCheckerCallback {

    /**
     * Allow use. App should proceed as normal.
     *
     * @param reason Policy.LICENSED or Policy.RETRY typically. (although in
     *            theory the policy can return Policy.NOT_LICENSED here as well)
     */
    public void allow(int reason);

    /**
     * Don't allow use. App should inform user and take appropriate action.
     *
     * @param reason Policy.NOT_LICENSED or Policy.RETRY. (although in theory
     *            the policy can return Policy.LICENSED here as well ---
     *            perhaps the call to the LVL took too long, for example)
     */
    public void dontAllow(int reason);

    ...
}

Thanks a lot!

user2342558
  • 5,567
  • 5
  • 33
  • 54

1 Answers1

1

When you are creating an instance of LicenseChecker class, you must provide an implementation of Policy interface.

Policy used by {@link LicenseChecker} to determine whether a user should have access to the application.

Based on official documentation in the source code, the provided policy decides wheater a user can use the application or not.

Now suppose due to the network problems, the license checker could not connect to the server. In this case, you should have your own policy to allow the user to use the application or not. You can define your own custom policy by implementing the Policy interface or using one of the predefined StrictPolicy or ServerManagedPolicy policies.

Please look at the Table 2 here. As you see, if response code is one of the ERROR_CONTACTING_SERVER or ERROR_SERVER_FAILURE, then the reason will be RETRY but your provided policy will decide about allowing the user to use the application or not. Now, I think it should be clear why Policy.RETRY could be a potential input for the allow method.

As I mentioned before, you can provide your own custom policy. Suppose your user has the license to use your application but based on your policy you don't want to allow the user to use your application at that moment. In this case dontAllow method with Policy.LICENSED will call. On the other hand, suppose your user doesn't have the license to use your application but you like to allow him/her to use your application. In this case allow method with Policy.NOT_LICENSED will call.

Mir Milad Hosseiny
  • 2,769
  • 15
  • 19