Last updated:2026-06-15

HarmonyOS SDK API Reference

  • MLinkSDK contains 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 the init interface.
    • Parameters:
      • enable: debug switch
    • Example:
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: UIAbilityContext
      • config: initialization configuration
    • Callback:
      • config.completion(error): initialization completion callback, error == null indicates the initialization process is complete
    • Example:
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, required
  • channel: channel information, optional
  • completion: 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:
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 launch
  • params: business parameters
  • source: data source
    • 0: unknown
    • 1: Scheme launch
    • 2: App Linking launch
    • 3: scene restoration
  • eventType: event type
    • 0: unknown
    • 1: install event
    • 2: launch event

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 paramKey is not provided, all parameters are returned. When provided, the parameter dictionary for the corresponding key is returned.
    • Parameters:
      • paramKey: optional, parameter key
      • handler: parameter callback
    • Callback:
      • Returns Map<string, Object> | null
    • Example:
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

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 pipeline
      • false: the SDK has ignored the link
    • Example:
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?

Copyright 2011-2026, jiguang.cn, All Rights Reserved. 粤ICP备12056275号-13 Shenzhen Hexun Huagu Information Technology Co., Ltd.

Open in Docs Center