中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
import { common, OpenLinkOptions } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; const DOMAIN = 0xeeee; const TAG: string = '[openLinkDemo]'; @Entry @Component struct Index { build() { RelativeContainer() { Button("Call StartAbilityForResult") .onClick(() => { let `context` = getContext(this) as common.UIAbilityContext; let `link`: string = 'https://www.example.com'; let `openLinkOptions`: OpenLinkOptions = { appLinkingOnly: true, parameters: { demo_key: 'demo_value' } }; try { context.openLink( `link`, `openLinkOptions`, (err, result) => { hilog.error(DOMAIN, TAG, `openLink callback error.code: ${JSON.stringify(err)}`); hilog.info(DOMAIN, TAG, `openLink callback result: ${JSON.stringify(result.resultCode)}`); hilog.info(DOMAIN, TAG, `openLink callback result data: ${JSON.stringify(result.want)}`); } ).then(() => { hilog.info(DOMAIN, TAG, `open link success.`); }).catch((err: BusinessError) => { hilog.error(DOMAIN, TAG, `open link failed, errCode ${JSON.stringify(err.code)}`); }); } catch (e) { hilog.error(DOMAIN, TAG, `exception occured, errCode ${JSON.stringify(e.code)}`); } }) .height('100%') .width('100%') } } }