元服务链接是专为开发者设计的密文URL服务,它可以被用户点击并直达拉起元服务任意页面,实现元服务的点击触达,即点即用。作为开发者,您可以为自己的元服务生成并配置专属的元服务链接,同时设置其有效期,精准把握用户访问的时效与范围,以将用户在时效内引导至元服务任意指定页面。
例如:当用户接收到“手机充值”的元服务链接后,他们可以通过点击该链接直接跳转至相应的元服务页面,实现一步直达的便捷体验。
元服务链接能力目前仅对HarmonyOS 5.0及以上版本的操作系统和HarmonyOS API 12及以上版本的元服务开放。


参数 | 说明 |
|---|---|
名称 | 配置元服务链接的名称。 |
链接URL | 配置元服务链接: 前缀为平台固定域名,开发者不能修改或自定义; 后缀字符串,默认由AGC自动生成,如需自行定义,应确保该字符串唯一且长度不超过100位。 |
链接URL预览 | 预览完整的元服务链接,支持复制。 |
选择元服务 | 选择需要配置链接的元服务的名称。 |
(可选)自定义参数 | 用于精确定位到元服务指定页面。需要按key=value的键值对形式输入,多个键值对之间以“&”分隔。例如:key1=value1&key2=value2&key3=value3... 具体请参见使用自定义参数跳转到指定的页面。 |
链接有效期 | 链接有效期生效时间段需在1~90天范围内;结束时间必须晚于当前时间。 |


开发者在创建元服务链接时,可设置自定义参数来精确定位到元服务指定页面。使用场景有如下两种:
subPackageName是系统保留KEY,仅用于子包提前安装,请勿作为自定义参数使用。
开发者跳转到指定页面,可以通过自定义参数,在运行时解析然后跳转到指定页面。跳转子页面实现示例:
pagePath=pages/menu
如果需要跳转到分包的页面,则pagePath需要配置为:@bundle:包名(bundleName)/模块名(moduleName)/路径/页面所在的文件名,例如:pagePath=@bundle:com.atomicservice.123456789/library/ets/pages/menu
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
export default class EntryAbility extends UIAbility {
pagePath: string = ''; // 用来保存通过router方式从元服务链接跳转到指定的页面
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
this.resolvePagePath(want);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
if(this.pagePath){
windowStage.loadContent(this.pagePath, (err) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
}
else{
windowStage.loadContent('pages/Index', (err) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
}
}
resolvePagePath(want: Want){
// 从want中获取传入的链接信息。如传入的url为:https://hoas.drcn.agconnect.link/9P7g
let uri = want?.uri;
console.info(`uri is: ${uri}`)
if (uri) {
//解析通过router跳转的页面
this.pagePath = want.parameters?.['pagePath'] as string;
console.info(`pagePath is: ${this.pagePath}`);
}
}
} navRouterName=ProductList
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
export default class EntryAbility extends UIAbility {
storage: LocalStorage|null = null; // 用来共享ability中的对象到页面中
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
console.info(`want in onCreate is ${JSON.stringify(want)}`)
this.resolveNavigationRouter(want);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}
onDestroy(): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', this.storage, (err) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
}
resolveNavigationRouter(want: Want){
// 从want中获取传入的链接信息。如传入的url为:https://hoas.drcn.agconnect.link/9P7g
let uri = want?.uri
console.info(`uri is: ${uri}`)
if (uri) {
//解析Navigation跳转页面的自定义参数
const navRouterName = want.parameters?.['navRouterName'] as string;
console.info(`navRouterName is: ${navRouterName}`)
const subPackageName = want.parameters?.['subPackageName'] as string;
console.info(`subPackageName is: ${subPackageName}`)
let para: Record<string, string> = { 'navRouterName': navRouterName , 'subPackageName': subPackageName};
this.storage = new LocalStorage(para);
}
}
} import { NavPushPathHelper } from '@kit.ArkUI';
let storage = LocalStorage.getShared()
@Entry(storage)
@Component
struct Index {
pathStack: NavPathStack = new NavPathStack()
helper: NavPushPathHelper = new NavPushPathHelper(this.pathStack)
@LocalStorageProp('subPackageName') subPackageName:string = ''
@LocalStorageProp('navRouterName') navRouterName:string = ''
build() {
//把页面栈对象传入Navigation
Navigation(this.pathStack) {
//首页的页面内容
}
.title('Main')
}
aboutToAppear(): void{
if(this.navRouterName){
if(this.subPackageName){
this.helper.pushPath(this.subPackageName, { name: this.navRouterName }, false)
.then(() => {
console.error('[pushPath]success.');
})
.catch((error: BusinessError) => {
console.error(`[pushPath]failed, error code = ${error.code}, error.message = ${error.message}.`);
});
}
else{
this.pathStack.pushPathByName(this.navRouterName, null, false)
}
}
}
} 在元服务链接页面的搜索框内,输入链接名称或网址可以进行模糊查询。

点击目标元服务链接“操作”列的“查看”,即可查看元服务链接的基本信息。

如果您的元服务链接状态为“已生效”,且已经配置了元服务标签,则支持编辑操作。


拉起方应用通过UIAbilityContext.openLink()接口,传入目标元服务链接,从而拉起目标元服务。
openLink接口提供“以App Linking打开元服务”的方式进行目标元服务页跳转,开发者可根据业务需求进行编译。
若有匹配的元服务,则直接打开目标元服务;否则,抛异常给开发者进行处理。
为验证元服务链接的配置是否正确,请参照如下示例代码:
import { common } from '@kit.AbilityKit';
export class GlobalContext {
private static context: common.UIAbilityContext;
public static initContext(context: common.UIAbilityContext): void {
GlobalContext.context = context;
}
public static getContext(): common.UIAbilityContext {
return GlobalContext.context;
}
} import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { GlobalContext } from '../common/GlobalContext';
@Entry
@Component
struct Index {
build() {
Button('start link', { type: ButtonType.Capsule, stateEffect: true })
.width('87%')
.height('5%')
.margin({ bottom: '12vp' })
.onClick(() => {
let context = GlobalContext.getContext();
// link 可替换成开发者自行配置的元服务链接
let link: string = "https://hoas.drcn.agconnect.link/9P7g";
context.openLink(link)
.then(() => {
console.info('openlink success.');
})
.catch((error: BusinessError) => {
console.error(`openlink failed. error:${JSON.stringify(error)}`);
});
})
}
} 以“手机充值”元服务为例,代码中link为该元服务首页的链接,当拉起方应用成功触发链接,弹窗提示“‘应用名’是否打开元服务”,点击“打开”则成功实现链接跳转元服务功能。
接口openLink还可以设置appLinkingOnly参数:
context.openLink(link, { appLinkingOnly: true })
.then(() => {
console.info('openlink success.');
})