Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.
HarmonyOS
Starting from API version 12, it is not recommended that third-party applications start other applications by specifying an ability (implicit Want mode). Instead, the linking mode is recommended.
This section describes how to switch from explicit Want mode to linking mode.
Install the application on your device. In the module.json5 file of the UIAbility, configure entities, actions, and uri under skills.
- {
- "module": {
- // ···
- "abilities": [
- // ···
- {
- // ···
- "skills": [
- {
- "entities": [
- "entity.system.browsable"
- ],
- "actions": [
- "ohos.want.action.viewData"
- ],
- "uris": [
- {
- "scheme": "https",
- "host": "www.example.com"
- }
- ],
- "domainVerify": true
- }
- ]
- },
- // ···
- ],
- // ···
- }
- }
Call openLink to trigger redirection. The link and options must be passed in, but the bundle name, module name, and ability name are not required. The system matches the application that meets the skills configuration based on the link.
- import { common, OpenLinkOptions } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
- import { hilog } from '@kit.PerformanceAnalysisKit';
-
- const TAG: string = '[UIAbilityComponentsOpenLink]';
- const DOMAIN_NUMBER: number = 0xFF00;
-
- @Entry
- @Component
- struct WantAbilityPage1 {
- build() {
- Button('start link', { type: ButtonType.Capsule, stateEffect: true })
- .width('87%')
- .height('5%')
- .margin({ bottom: '12vp' })
- .onClick(() => {
- let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
- // When using startAbility to explicitly start other UIAbilities, the openLink API is recommended.
- // let want: Want = {
- // bundleName: "com.test.example",
- // moduleName: "entry",
- // abilityName: "EntryAbility"
- // };
- // try {
- // context.startAbility(want)
- // .then(() => {
- // hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success.');
- // }).catch((err: BusinessError) => {
- // hilog.error(DOMAIN_NUMBER, TAG, `startAbility failed. Code is ${err.code}, message is ${err.message}`);
- // })
- // } catch (paramError) {
- // hilog.error(DOMAIN_NUMBER, TAG, `Failed to startAbility. Code is ${paramError.code},\
- // message is ${paramError.message}`);
- // }
- let link: string = 'https://www.example.com';
- let openLinkOptions: OpenLinkOptions = {
- // Specify whether the matched abilities options must pass App Linking domain name verification.
- appLinkingOnly: true,
- // Same as parameter in want, which is used to transfer parameters.
- parameters: {demo_key: 'demo_value'}
- };
-
- try {
- context.openLink(link, openLinkOptions)
- .then(() => {
- hilog.info(DOMAIN_NUMBER, TAG, 'open link success.');
- }).catch((err: BusinessError) => {
- hilog.error(DOMAIN_NUMBER, TAG, `open link failed. Code is ${err.code}, message is ${err.message}`);
- })
- } catch (paramError) {
- hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`);
- }
- })
- }
- }
Install the application on your device. In the module.json5 file of the UIAbility, configure entities, actions, and uri under skills.
- {
- "module": {
- // ···
- "abilities": [
- // ···
- {
- // ···
- "skills": [
- {
- "entities": [
- "entity.system.browsable"
- ],
- "actions": [
- "ohos.want.action.viewData"
- ],
- "uris": [
- {
- "scheme": "https",
- "host": "www.example.com"
- }
- ],
- "domainVerify": true
- }
- ]
- },
- // ···
- ],
- // ···
- }
- }
Call openLink to trigger redirection. The link and options must be passed in, but the bundle name, module name, and ability name are not required. The system matches the application that meets the skills configuration based on the link. AbilityResult is transferred to the callback function through input parameters and returned to the caller application when the UIAbility is terminated. The startup success or failure result is returned through a promise.
- import { common, OpenLinkOptions } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
- import { hilog } from '@kit.PerformanceAnalysisKit';
-
- const TAG: string = '[UIAbilityComponentsOpenLink]';
- const DOMAIN_NUMBER: number = 0xFF00;
-
- @Entry
- @Component
- struct WantAbilityPage2 {
- build() {
- Button('start link', { type: ButtonType.Capsule, stateEffect: true })
- .width('87%')
- .height('5%')
- .margin({ bottom: '12vp' })
- .onClick(() => {
- let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
- // When using startAbility to explicitly start other UIAbilities, the openLink API is recommended.
- // let want: Want = {
- // bundleName: "com.test.example",
- // moduleName: "entry",
- // abilityName: "EntryAbility"
- // };
- // try {
- // context.startAbilityForResult(want)
- // .then((data) => {
- // hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success. data: ' + JSON.stringify(data));
- // }).catch((err: BusinessError) => {
- // hilog.error(DOMAIN_NUMBER, TAG, `startAbility failed. Code is ${err.code}, message is ${err.message}`);
- // })
- // } catch (paramError) {
- // hilog.error(DOMAIN_NUMBER, TAG, `Failed to startAbility. Code is ${paramError.code}, \
- // message is ${paramError.message}`);
- // }
- let link: string = 'https://www.example.com';
- let openLinkOptions: OpenLinkOptions = {
- // Specify whether the matched abilities options must pass App Linking domain name verification.
- appLinkingOnly: true,
- // Same as parameter in want, which is used to transfer parameters.
- parameters: {demo_key: 'demo_value'}
- };
-
- try {
- context.openLink(link, openLinkOptions, (err, data) => {
- // AbilityResult callback function, which is triggered only when the started UIAbility is terminated.
- hilog.info(DOMAIN_NUMBER, TAG, 'open link success. Callback result: ' + JSON.stringify(data));
- }).then(() => {
- hilog.info(DOMAIN_NUMBER, TAG, 'open link success.');
- }).catch((err: BusinessError) => {
- hilog.error(DOMAIN_NUMBER, TAG, `open link failed. Code is ${err.code}, message is ${err.message}`);
- })
- } catch (paramError) {
- hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`);
- }
- })
- }
- }
Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Quick start
Helps you find desired resources with ease.