activate static method
Activates a product using the supplied license key.
Starts an activation flow for productId using licenseKey (a UUID v4).
The operation is asynchronous and the onComplete callback reports final
status and a hint string with supplemental information.
Parameters
applicationId: The application identifier owning the activation.licenseKey: The license key (UUID v4) used to identify the activation. Use the key obtained from generateLicenseKey or provided by Magic Lane.productId: The product identifier to activate. Defaults to ProductID.core.onComplete: Callback invoked on completion. The callback receives:- GemError.success: Activation succeeded.
- GemError.required: No internet; try again or complete the activation offline. Follow the steps from the manual for manual offline activation.
- GemError.invalidInput: Invalid input; check the
hintfor details. - GemError.io: IO error when accessing the license file.
- GemError.noMemory: Allocation failed on the platform.
- GemError.networkFailed: Network request failed to start.
Returns
- TaskHandler: A task handle when the activation request started successfully, otherwise
null.
Also see:
- generateLicenseKey - Generate a license key for activation.
- completeActivation - Complete an activation that required manual steps.
- getActivationsForProduct - List activations present on the device.
- deactivate - Deactivates a product previously activated with a license key.
- SdkSettings - Manage app tokens and other settings.
Implementation
static TaskHandler? activate({
required final String applicationId,
required final String licenseKey,
final String productId = ProductID.core,
required final void Function(GemError error, String hint) onComplete,
}) {
final EventDrivenProgressListener progListener =
EventDrivenProgressListener();
GemKitPlatform.instance.registerEventHandler(progListener.id, progListener);
progListener.registerOnCompleteWithData((
final int err,
final String hint,
final Map<dynamic, dynamic> json,
) {
GemKitPlatform.instance.unregisterEventHandler(progListener.id);
onComplete(GemErrorExtension.fromCode(err), hint);
});
final OperationResult resultString = staticMethod(
'ActivationService',
'activate',
args: <String, dynamic>{
'applicationId': applicationId,
'licenseKey': licenseKey,
'productId': productId,
'listener': progListener.id,
},
);
final GemError errorCode = GemErrorExtension.fromCode(
resultString['result'],
);
if (errorCode != GemError.success) {
return null;
}
return TaskHandlerImpl(progListener.id);
}