Checking the License Data of the Supplied License Key

The checkLicenseKey() function checks the Server for the license data for the supplied licenseKey. Whereas checkLicenseKey() is a passive check, setLicenseKey() changes the license key.

The checkLicenseKey() function can be called between startSDK() and stopSDK(), and can be called zero or more times.

The checkLicenseKey() function is a synchronous function returning when all functionality is completed.

checkLicenseKey()

RUIResult checkLicenseKey(String licenseKey, List<RUIKeyData> licenseArray)

Parameters

The checkLicenseKey() function has the following parameters.

checkLicenseKey() Parameters

Parameter

Description

licenseKey (String)

The license key to be checked. This value cannot be empty.

The function accepts a String parameter that is the license key itself a List<RUIKeyData> array of length 5 that it fills with the returned result. You may use the following constants to refer to the required value by its index from the RUIKeyIndex enum:

LICENSE_ARRAY_INDEX_KEY_TYPE        (0)

LICENSE_ARRAY_INDEX_KEY_EXPIRED     (1)

LICENSE_ARRAY_INDEX_KEY_ACTIVE      (2)

LICENSE_ARRAY_INDEX_KEY_BLACKLISTED (3)

LICENSE_ARRAY_INDEX_KEY_WHITELISTED (4)

Each of the values 1 through 4 will be set to either 0 or 1 that refers to false or true respectively. The first value (RUIKeyIndex.TYPE_INDEX) will be set to a number between 0 and 7 (inclusive) that refers to the 8 possible license types listed below. The values may also be -1 that means “Unknown”. The following are the possible license types:

UNCHANGED  (-1)

EVALUATION (0)

PURCHASED  (1)

REEWARE   (2)

UNKNOWN    (3)

NFR        (4) - Key Type is Not For Resale

CUSTOM1    (5)

CUSTOM2    (6)

CUSTOM3    (7)

The following are the possible key status values:

UNCHANGED (-1)—Key Status is Unchanged (when in parameter) or Unknown (when out parameter).
NO (0)—Key Status is No.
YES (1)—Key Status is Yes.

licenseArray (List<RUIKeyData> length of 5)

The vector that will be filled to contain the license status flags.

Returns

The checkLicenseKey() function returns one of the RUIState enum values below:

checkLicenseKey() Returns

Return

Description

OK

Function successful.

SDK_INTERNAL_ERROR_FATAL

Irrecoverable internal fatal error. No further API calls should be made.

SDK_ABORTED

A required New Registration has failed, and hence the SDK is aborted. stopSDK() is possible.

SDK_PERMANENTLY_DISABLED

The Server has instructed a permanent disable.

SDK_SUSPENDED

The Server has instructed a temporary back-off.

SDK_OPTED_OUT

Instance has been instructed by the application to opt-out.

CONFIG_NOT_CREATED

Configuration has not been successfully created.

SDK_ALREADY_STOPPED

SDK has already been successfully stopped.

SDK_NOT_STARTED

SDK has not been successfully started.

INVALID_PARAMETER_EXPECTED_NON_EMPTY

Some API parameter is expected to be non-empty, and is not.

TIME_THRESHOLD_NOT_REACHED

The API call frequency threshold (set by the Server) has not been reached.

NETWORK_CONNECT_ERROR

Not able to reach the Server.

NETWORK_SERVER_ERROR

Error while communicating with the Server.

NETWORK_RESPONSE_INVALID

Message format error while communicating with the Server.

Code Example

//Test a license key

mySDK.startSDK(); //...; //Creation and initialization shown in other snippets.

String myProductKey = "xyz";

List<RUIKeyData> licenseResult = new ArrayList<>(5);

 

RUIResult rc = mySDK.checkLicenseKey(myProductKey, licenseResult);

if(rc == RUIResult.OK)

{

    if (licenseResult.get(RUISDK.LICENSE_ARRAY_INDEX_KEY_TYPE) == RUIKeyType.UNCHANGED) {

        System.out.println("License Key is unchanged");

    } else {

        String myType = "License type = " + licenseResult.get(RUISDK.LICENSE_ARRAY_INDEX_KEY_TYPE).getId();

        System.out.println(myType);

    }

    //Check if the license key is activated

    if (licenseResult.get(RUISDK.LICENSE_ARRAY_INDEX_KEY_ACTIVE) == RUIKeyStatus.YES){

        System.out.println("License Active");

    } else if (licenseResult.get(RUISDK.LICENSE_ARRAY_INDEX_KEY_ACTIVE) == RUIKeyStatus.NO) {

        System.out.println("License Inactive");

    } else {

        System.out.println("License status unknown");

    }

 

    //check if license key is blacklisted

    if (licenseResult.get(RUISDK.LICENSE_ARRAY_INDEX_KEY_BLACKLISTED) == RUIKeyStatus.YES){

        System.out.println("Key is black listed");

    } else if (licenseResult.get(RUISDK.LICENSE_ARRAY_INDEX_KEY_BLACKLISTED) == RUIKeyStatus.NO) {

        System.out.println("Key is NOT black listed");

    } else {

        System.out.println("Key blank listed status is unknown");

    }

 

    //Check if license key is expired

    if (licenseResult.get(RUISDK.LICENSE_ARRAY_INDEX_KEY_EXPIRED) == RUIKeyStatus.YES){

        System.out.println("Key is expired");

    } else if (licenseResult.get(RUISDK.LICENSE_ARRAY_INDEX_KEY_EXPIRED) == RUIKeyStatus.NO) {

        System.out.println("Key is NOT expired");

    } else {

        System.out.println("Key expiration status is unknown");

    }

 

    //Check if license key is white listed

    if (licenseResult.get(RUISDK.LICENSE_ARRAY_INDEX_KEY_WHITELISTED) == RUIKeyStatus.YES){

        System.out.println("Key is white listed");

    } else if (licenseResult.get(RUISDK.LICENSE_ARRAY_INDEX_KEY_WHITELISTED) == RUIKeyStatus.NO) {

        System.out.println("Key is NOT white listed");

    } else {

        System.out.println("Key white listed status is unknown");

    }

} else {

    System.out.println("Failed to invoke function checkLicenseKey()");

}