Last updated:2026-06-15
HarmonyOS SDK API Reference
MLinkSDKcontains all public interfaces of the SDK
Set Debug Mode
Supported Versions
Supported since version 1.0.0
Interface Definition
- MLinkSDK.setDebug(enable: boolean)
- Description:
- Sets whether to enable debug mode. When set to
true, more log information will be printed. It is recommended to call this before theinitinterface.
- Sets whether to enable debug mode. When set to
- Parameters:
enable: debug switch
- Example:
- Description:
MLinkSDK.setDebug(true);
MLinkSDK.setDebug(true);
This code block is shown in the floating window
SDK Initialization
Supported Versions
Supported since version 1.0.0
Interface Definition
- MLinkSDK.init(context: common.UIAbilityContext, config: MLinkConfig)
- Description:
- Initialization interface.
- Parameters:
context:UIAbilityContextconfig: initialization configuration
- Callback:
config.completion(error): initialization completion callback,error == nullindicates the initialization process is complete
- Example:
- Description:
const config = new MLinkConfig();
config.appKey = "your AppKey";
config.completion = (error) => {
if (error) {
console.error(`init failed: ${error.message}`);
}
};
MLinkSDK.init(this.context, config);
const config = new MLinkConfig();
config.appKey = "your AppKey";
config.completion = (error) => {
if (error) {
console.error(`init failed: ${error.message}`);
}
};
MLinkSDK.init(this.context, config);
This code block is shown in the floating window
Initialization Parameter MLinkConfig
export class MLinkConfig {
appKey: string = ''
channel?: string
completion?: (error?: Error | null) => void
}
export class MLinkConfig {
appKey: string = ''
channel?: string
completion?: (error?: Error | null) => void
}
This code block is shown in the floating window
Parameter descriptions:
appKey: application identifier, requiredchannel: channel information, optionalcompletion: initialization completion callback, optional
Register Unified Callback
Supported Versions
Supported since version 1.0.0
Interface Definition
- MLinkSDK.registerHandler(handler: MLinkHandler)
- Description:
- Registers a unified callback entry. The SDK returns results through this callback when a valid mlink is parsed.
- Parameters:
handler: callback function
- Example:
- Description:
MLinkSDK.registerHandler((response) => {
if (!response) {
return;
}
console.info(`url=${response.url ?? ''}`);
});
MLinkSDK.registerHandler((response) => {
if (!response) {
return;
}
console.info(`url=${response.url ?? ''}`);
});
This code block is shown in the floating window
Callback Model MLinkResponse
export class MLinkResponse {
url?: string
params?: Record<string, Object>
source: number = 0
eventType: number = 0
}
export class MLinkResponse {
url?: string
params?: Record<string, Object>
source: number = 0
eventType: number = 0
}
This code block is shown in the floating window
Field descriptions:
url: target link after launchparams: business parameterssource: data source0: unknown1: Scheme launch2: App Linking launch3: scene restoration
eventType: event type0: unknown1: install event2: launch event
Get MLink Parameters
Supported Versions
Supported since version 1.0.0
Interface Definition
- MLinkSDK.getMLinkParam(paramKey?: string, handler?: (params: Map<string, Object> | null) => void)
- Description:
- Retrieves mlink parameters. When
paramKeyis not provided, all parameters are returned. When provided, the parameter dictionary for the corresponding key is returned.
- Retrieves mlink parameters. When
- Parameters:
paramKey: optional, parameter keyhandler: parameter callback
- Callback:
- Returns
Map<string, Object> | null
- Returns
- Example:
- Description:
MLinkSDK.getMLinkParam(undefined, (params) => {
if (!params) {
return;
}
params.forEach((value, key) => {
console.info(`${key}=${value}`);
});
});
MLinkSDK.getMLinkParam('scene', (params) => {
if (!params) {
return;
}
console.info(params.get('scene'));
});
MLinkSDK.getMLinkParam(undefined, (params) => {
if (!params) {
return;
}
params.forEach((value, key) => {
console.info(`${key}=${value}`);
});
});
MLinkSDK.getMLinkParam('scene', (params) => {
if (!params) {
return;
}
console.info(params.get('scene'));
});
This code block is shown in the floating window
Route Link
Supported Versions
Supported since version 1.0.0
Interface Definition
- MLinkSDK.routeLink(url: string): boolean
- Description:
- Unified routing entry that handles links returned from Scheme, App Linking, and scene restoration.
- Parameters:
url: the link to be processed
- Return Value:
true: the SDK has accepted the link and entered the processing pipelinefalse: the SDK has ignored the link
- Example:
- Description:
const handled = MLinkSDK.routeLink("mlinkdemo://open/home?scene=demo");
console.info(`handled=${handled}`);
const handled = MLinkSDK.routeLink("mlinkdemo://open/home?scene=demo");
console.info(`handled=${handled}`);
This code block is shown in the floating window
Was this document helpful?