harmony 鸿蒙@ohos.app.ability.InsightIntentExecutor (意图调用执行基类)
@ohos.app.ability.InsightIntentExecutor (意图调用执行基类)
本模块提供意图调用执行基类,开发者通过意图调用执行基类对接端侧意图框架,实现响应意图调用的业务逻辑。开发者接入意图框架时,在意图配置文件中声明对接的意图名称、意图接入方式等,系统根据用户交互和开发者的意图配置文件进行意图调用,触发相应的意图调用执行回调。
说明:
本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
本模块接口仅可在Stage模型下使用。
导入模块
import { InsightIntentExecutor } from '@kit.AbilityKit';
InsightIntentExecutor
表示意图调用执行基类。
属性
模型约束:此接口仅可在Stage模型下使用。
原子化服务API:从API version 11开始,该接口支持在原子化服务中使用。
系统能力:SystemCapability.Ability.AbilityRuntime.Core
名称 | 类型 | 只读 | 可选 | 说明 |
---|---|---|---|---|
context | InsightIntentContext | 否 | 否 | 意图调用执行上下文。 |
onExecuteInUIAbilityForegroundMode
onExecuteInUIAbilityForegroundMode(name: string, param: Record
当意图调用是将UIAbility在前台显示时,触发该回调。支持同步返回和使用Promise异步返回。
模型约束:此接口仅可在Stage模型下使用。
原子化服务API:从API version 11开始,该接口支持在原子化服务中使用。
系统能力:SystemCapability.Ability.AbilityRuntime.AbilityCore
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
name | string | 是 | 意图调用名称。 |
param | Record |
是 | 意图调用参数。 |
pageLoader | window.WindowStage | 是 | 页面加载器。 |
返回值:
类型 | 说明 |
---|---|
insightIntent.ExecuteResult | 意图调用执行结果。 |
Promise<insightIntent.ExecuteResult> | Promise对象,返回意图调用执行结果。 |
示例:
直接返回意图调用的结果,示例如下:
import { InsightIntentExecutor, insightIntent } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';
import { hilog } from '@kit.PerformanceAnalysisKit';
export default class IntentExecutorImpl extends InsightIntentExecutor {
onExecuteInUIAbilityForegroundMode(name: string, param: Record<string, Object>, pageLoader: window.WindowStage): insightIntent.ExecuteResult {
let result: insightIntent.ExecuteResult;
if (name !== 'SupportedInsightIntentName') {
hilog.warn(0x0000, 'testTag', 'Unsupported insight intent %{public}s', name);
result = {
// decided by developer
code: 404,
result: {
message: 'Unsupported insight intent.',
}
};
return result;
}
// if developer need load content
pageLoader.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
} else {
hilog.info(0x0000, 'testTag', '%{public}s', 'Succeeded in loading the content');
}
});
result = {
code: 0,
result: {
message: 'Execute insight intent succeed.',
}
};
return result;
}
}
使用Promise异步返回意图调用的结果,示例如下:
import { InsightIntentExecutor, insightIntent } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';
import { hilog } from '@kit.PerformanceAnalysisKit';
async function executeInsightIntent(param: Record<string, Object>): Promise<insightIntent.ExecuteResult> {
return new Promise((resolve, reject) => {
let result: insightIntent.ExecuteResult = {
code: 0,
result: {
message: 'Execute insight intent succeed.',
}
};
resolve(result);
})
}
export default class IntentExecutorImpl extends InsightIntentExecutor {
async onExecuteInUIAbilityForegroundMode(name: string, param: Record<string, Object>, pageLoader: window.WindowStage): Promise<insightIntent.ExecuteResult> {
let result: insightIntent.ExecuteResult;
if (name !== 'SupportedInsightIntentName') {
hilog.warn(0x0000, 'testTag', 'Unsupported insight intent %{public}s', name);
result = {
// decided by developer
code: 404,
result: {
message: 'Unsupported insight intent.',
}
};
return result;
}
result = await executeInsightIntent(param);
return result;
}
}
onExecuteInUIAbilityBackgroundMode
onExecuteInUIAbilityBackgroundMode(name: string, param: Record
当意图调用是将UIAbility在后台拉起时,触发该回调。支持同步返回和使用Promise异步返回。
模型约束:此接口仅可在Stage模型下使用。
原子化服务API:从API version 11开始,该接口支持在原子化服务中使用。
系统能力:SystemCapability.Ability.AbilityRuntime.AbilityCore
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
name | string | 是 | 意图调用名称。 |
param | Record |
是 | 意图调用参数。 |
返回值:
类型 | 说明 |
---|---|
insightIntent.ExecuteResult | 意图调用执行结果。 |
Promise<insightIntent.ExecuteResult> | Promise对象,返回意图调用执行结果。 |
示例:
直接返回意图调用的结果,示例如下:
import { InsightIntentExecutor, insightIntent } from '@kit.AbilityKit';
export default class IntentExecutorImpl extends InsightIntentExecutor {
onExecuteInUIAbilityBackgroundMode(name: string, param: Record<string, Object>): insightIntent.ExecuteResult {
let result: insightIntent.ExecuteResult = {
code: 0,
result: {
message: 'Execute insight intent succeed.',
}
};
return result;
}
}
使用Promise异步返回意图调用的结果,示例如下:
import { InsightIntentExecutor, insightIntent } from '@kit.AbilityKit';
async function executeInsightIntent(param: Record<string, Object>): Promise<insightIntent.ExecuteResult> {
return new Promise((resolve, reject) => {
let result: insightIntent.ExecuteResult = {
code: 0,
result: {
message: 'Execute insight intent succeed.',
}
};
resolve(result);
})
}
export default class IntentExecutorImpl extends InsightIntentExecutor {
async onExecuteInUIAbilityBackgroundMode(name: string, param: Record<string, Object>): Promise<insightIntent.ExecuteResult> {
let result: insightIntent.ExecuteResult = await executeInsightIntent(param);
return result;
}
}
onExecuteInUIExtensionAbility
onExecuteInUIExtensionAbility(name: string, param: Record
当意图调用是拉起UIExtensionAbility时,触发该回调。支持同步返回和使用Promise异步返回。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
name | string | 是 | 意图调用名称。 |
param | Record |
是 | 意图调用参数。 |
pageLoader | UIExtensionContentSession | 是 | 页面加载器。 |
返回值:
类型 | 说明 |
---|---|
insightIntent.ExecuteResult | 意图调用执行结果。 |
Promise<insightIntent.ExecuteResult> | Promise对象,返回意图调用执行结果。 |
示例:
直接返回意图调用的结果,示例如下:
import { InsightIntentExecutor, insightIntent, UIExtensionContentSession } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
export default class IntentExecutorImpl extends InsightIntentExecutor {
onExecuteInUIExtensionAbility(name: string, param: Record<string, Object>, pageLoader: UIExtensionContentSession): insightIntent.ExecuteResult {
let result: insightIntent.ExecuteResult;
if (name !== 'SupportedInsightIntentName') {
hilog.warn(0x0000, 'testTag', 'Unsupported insight intent %{public}s', name);
result = {
// decided by developer
code: 404,
result: {
message: 'Unsupported insight intent.',
}
};
return result;
}
// if developer need load content
pageLoader.loadContent('pages/Index');
result = {
code: 0,
result: {
message: 'Execute insight intent succeed.',
}
};
return result;
}
}
使用Promise异步返回意图调用的结果,示例如下:
import { InsightIntentExecutor, insightIntent, UIExtensionContentSession } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
async function executeInsightIntent(param: Record<string, Object>): Promise<insightIntent.ExecuteResult> {
return new Promise((resolve, reject) => {
let result: insightIntent.ExecuteResult = {
code: 0,
result: {
message: 'Execute insight intent succeed.',
}
};
resolve(result);
})
}
export default class IntentExecutorImpl extends InsightIntentExecutor {
async onExecuteInUIExtensionAbility(name: string, param: Record<string, Object>, pageLoader: UIExtensionContentSession): Promise<insightIntent.ExecuteResult> {
let result: insightIntent.ExecuteResult;
if (name !== 'SupportedInsightIntentName') {
hilog.warn(0x0000, 'testTag', 'Unsupported insight intent %{public}s', name);
result = {
// decided by developer
code: 404,
result: {
message: 'Unsupported insight intent.',
}
};
return result;
}
result = await executeInsightIntent(param);
return result;
}
}
onExecuteInServiceExtensionAbility
onExecuteInServiceExtensionAbility(name: string, param: Record
当意图调用是拉起ServiceExtensionAbility时,触发该回调。支持同步返回和使用Promise异步返回。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
name | string | 是 | 意图调用名称。 |
param | Record |
是 | 意图调用参数。 |
返回值:
类型 | 说明 |
---|---|
insightIntent.ExecuteResult | 意图调用执行结果。 |
Promise<insightIntent.ExecuteResult> | Promise对象,返回意图调用执行结果。 |
示例:
直接返回意图调用的结果,示例如下:
import { InsightIntentExecutor, insightIntent } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
export default class IntentExecutorImpl extends InsightIntentExecutor {
onExecuteInServiceExtensionAbility(name: string, param: Record<string, Object>): insightIntent.ExecuteResult {
let result: insightIntent.ExecuteResult;
if (name !== 'SupportedInsightIntentName') {
hilog.warn(0x0000, 'testTag', 'Unsupported insight intent %{public}s', name);
result = {
// decided by developer
code: 404,
result: {
message: 'Unsupported insight intent.',
}
};
return result;
}
result = {
code: 0,
result: {
message: 'Execute insight intent succeed.',
}
};
return result;
}
}
使用Promise异步返回意图调用的结果,示例如下:
import { InsightIntentExecutor, insightIntent } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
async function executeInsightIntent(param: Record<string, Object>): Promise<insightIntent.ExecuteResult> {
return new Promise((resolve, reject) => {
let result: insightIntent.ExecuteResult = {
code: 0,
result: {
message: 'Execute insight intent succeed.',
}
};
resolve(result);
});
}
export default class IntentExecutorImpl extends InsightIntentExecutor {
async onExecuteInServiceExtensionAbility(name: string, param: Record<string, Object>): Promise<insightIntent.ExecuteResult> {
let result: insightIntent.ExecuteResult;
if (name !== 'SupportedInsightIntentName') {
hilog.warn(0x0000, 'testTag', 'Unsupported insight intent %{public}s', name);
result = {
// decided by developer
code: 404,
result: {
message: 'Unsupported insight intent.',
}
};
return result;
}
result = await executeInsightIntent(param);
return result;
}
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙OH_NativeBundle_ApplicationInfo
harmony 鸿蒙OH_NativeBundle_ElementName
harmony 鸿蒙ability_base_common.h
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦