0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看威廉希尔官方网站 视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

鸿蒙开发接口Ability框架:【@ohos.wantAgent (WantAgent模块)】

jf_46214456 来源:jf_46214456 作者:jf_46214456 2024-05-13 17:35 次阅读

WantAgent模块

WantAgent模块提供了触发、取消、比较WantAgent实例和获取bundle名称的能力,包括创建WantAgent实例、获取实例的用户ID、获取want信息等。

说明:

本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import WantAgent from '@ohos.wantAgent';

开发前请熟悉鸿蒙开发指导文档:[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]

WantAgent.getWantAgent

getWantAgent(info: WantAgentInfo, callback: AsyncCallback): void

创建WantAgent(callback形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数

名称可读可写类型必填描述
infoWantAgentInfoWantAgent信息。
callbackAsyncCallback创建WantAgent的回调方法。

示例:

import WantAgent from '@ohos.wantAgent';

//getWantAgent回调
function getWantAgentCallback(err, data) {
	console.info("========================== >getWantAgentCallback======================= >");
}
//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

WantAgent.getWantAgent

getWantAgent(info: WantAgentInfo): Promise

创建WantAgent(Promise形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
infoWantAgentInfoWantAgent信息。

返回值:

类型说明
Promise以Promise形式返回WantAgent。

示例:

import WantAgent from '@ohos.wantAgent';


//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
	console.info("========================== >getWantAgentCallback======================= >");
});

WantAgent.getBundleName

getBundleName(agent: WantAgent, callback: AsyncCallback): void

获取WantAgent实例的包名(callback形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。
callbackAsyncCallback获取WantAgent实例的包名的回调方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent;

//getWantAgent回调
function getWantAgentCallback(err, data) {
	console.info("========================== >getWantAgentCallback======================= >");
    if (err.code == 0) {
    	wantAgent = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

//getBundleName回调
function getBundleNameCallback(err, data) {
	console.info("========================== >getBundleNameCallback======================= >");
}
WantAgent.getBundleName(wantAgent, getBundleNameCallback)

WantAgent.getBundleName

getBundleName(agent: WantAgent): Promise

获取WantAgent实例的包名(Promise形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。

返回值:

类型说明
Promise以Promise形式返回获取WantAgent实例的包名。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent;

//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
	console.info("========================== >getWantAgentCallback======================= >");
    wantAgent = data;
});

WantAgent.getBundleName(wantAgent).then((data) = > {
	console.info("========================== >getBundleNameCallback======================= >");
});

WantAgent.getUid

getUid(agent: WantAgent, callback: AsyncCallback): void

获取WantAgent实例的用户ID(callback形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。
callbackAsyncCallback获取WantAgent实例的用户ID的回调方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent;

//getWantAgent回调
function getWantAgentCallback(err, data) {
	console.info("========================== >getWantAgentCallback======================= >");
    if (err.code == 0) {
    	wantAgent = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

//getUid回调
function getUidCallback(err, data) {
	console.info("========================== >getUidCallback======================= >");
}
WantAgent.getUid(wantAgent, getUidCallback)

WantAgent.getUid

getUid(agent: WantAgent): Promise

获取WantAgent实例的用户ID(Promise形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。

返回值:

类型说明
Promise以Promise形式返回获取WantAgent实例的用户ID。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent;

//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
	console.info("========================== >getWantAgentCallback======================= >");
    wantAgent = data;
});

WantAgent.getUid(wantAgent).then((data) = > {
	console.info("========================== >getUidCallback======================= >");
});

WantAgent.getWant

getWant(agent: WantAgent, callback: AsyncCallback): void

获取WantAgent对象的want(callback形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

系统API : 此接口为系统接口,三方应用不支持调用。

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。
callbackAsyncCallback获取WantAgent对象want的回调方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent;

//getWantAgent回调
function getWantAgentCallback(err, data) {
	console.info("========================== >getWantAgentCallback======================= >");
    if (err.code == 0) {
    	wantAgent = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

//getWant回调
function getWantCallback(err, data) {
	console.info("========================== >getWantCallback======================= >");
}
WantAgent.getWant(wantAgent, getWantCallback)

WantAgent.getWant

getWant(agent: WantAgent): Promise

获取WantAgent对象的want(Promise形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

系统API : 此接口为系统接口,三方应用不支持调用。

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。

返回值:

类型说明
Promise以Promise形式返回获取WantAgent对象的want。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent;

//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
	console.info("========================== >getWantAgentCallback======================= >");
    wantAgent = data;
});

WantAgent.getWant(wantAgent).then((data) = > {
	console.info("========================== >getWantCallback======================= >");
});

WantAgent.cancel

cancel(agent: WantAgent, callback: AsyncCallback): void

取消WantAgent实例(callback形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。
callbackAsyncCallback取消WantAgent实例的回调方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent;

//getWantAgent回调
function getWantAgentCallback(err, data) {
	console.info("========================== >getWantAgentCallback======================= >");
    if (err.code == 0) {
    	wantAgent = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

//cancel回调
function cancelCallback(err, data) {
	console.info("========================== >cancelCallback======================= >");
}
WantAgent.cancel(wantAgent, cancelCallback)

WantAgent.cancel

cancel(agent: WantAgent): Promise

取消WantAgent实例(Promise形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。

返回值:

类型说明
Promise以Promise形式获取异步返回结果。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent;

//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
	console.info("========================== >getWantAgentCallback======================= >");
    wantAgent = data;
});

WantAgent.cancel(wantAgent).then((data) = > {
	console.info("========================== >cancelCallback======================= >");
});

WantAgent.trigger

trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback): void

主动激发WantAgent实例(callback形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。
triggerInfoTriggerInfoTriggerInfo对象。
callbackAsyncCallback主动激发WantAgent实例的回调方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent;

//getWantAgent回调
function getWantAgentCallback(err, data) {
	console.info("========================== >getWantAgentCallback======================= >");
    if (err.code == 0) {
    	wantAgent = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

//trigger回调
function triggerCallback(data) {
	console.info("========================== >triggerCallback======================= >");
}

var triggerInfo = {
    code:0
}
WantAgent.trigger(wantAgent, triggerInfo, triggerCallback)

WantAgent.equal

equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback): void

判断两个WantAgent实例是否相等(callback形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。
otherAgentWantAgentWantAgent对象。
callbackAsyncCallback判断两个WantAgent实例是否相等的回调方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent1;
var wantAgent2;

//getWantAgent回调
function getWantAgentCallback(err, data) {
	console.info("========================== >getWantAgentCallback======================= >");
    if (err.code == 0) {
    	wantAgent1 = data;
        wantAgent2 = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

//equal回调
function equalCallback(err, data) {
	console.info("========================== >equalCallback======================= >");
}
WantAgent.equal(wantAgent1, wantAgent2, equalCallback)

WantAgent.equal

equal(agent: WantAgent, otherAgent: WantAgent): Promise

判断两个WantAgent实例是否相等(Promise形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。
otherAgentWantAgentWantAgent对象。

返回值:

类型说明
Promise以Promise形式返回获取判断两个WantAgent实例是否相等的结果。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent对象
var wantAgent1;
var wantAgent2;

//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
	console.info("========================== >getWantAgentCallback======================= >");
    wantAgent1 = data;
    wantAgent2 = data;
});

WantAgent.equal(wantAgent1, wantAgent2).then((data) = > {
	console.info("========================== >equalCallback======================= >");
});

WantAgent.getOperationType9+

getOperationType(agent: WantAgent, callback: AsyncCallback): void;

获取一个WantAgent的OperationType信息(callback形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。
callbackAsyncCallback获取一个WantAgent的OperationType信息的回调方法。

示例:

import WantAgent from '@ohos.wantAgent';

//wantAgent对象
var wantAgent;

//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
	console.info("========================== >getWantAgentCallback======================= >");
    wantAgent = data;
});

WantAgent.getOperationType(wantAgent, (OperationType) = > {
    console.log('----------- getOperationType ----------, OperationType: ' + OperationType);
})

WantAgent.getOperationType9+

getOperationType(agent: WantAgent): Promise;

获取一个WantAgent的OperationType信息(Promise形式)。

系统能力 :SystemCapability.Ability.AbilityRuntime.Core

参数:

名称可读可写类型必填描述
agentWantAgentWantAgent对象。

返回值:

类型说明
Promise以Promise形式返回获取optionType的结果。

示例:

import WantAgent from '@ohos.wantAgent';

//wantAgent对象
var wantAgent;

//WantAgentInfo对象
var wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.neu.setResultOnAbilityResultTest1",
            abilityName: "com.example.test.MainAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [false, true, false],
                mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
	console.info("========================== >getWantAgentCallback======================= >");
    wantAgent = data;
});

WantAgent.getOperationType(wantAgent).then((OperationType) = > {
    console.log('getOperationType success, OperationType: ' + OperationType);
}).catch((err) = > {
    console.log('getOperationType fail, err: ' + err);
})

WantAgentInfo

系统能力 :以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

名称可读可写类型必填描述
wantsArray将被执行的动作列表。
operationTypewantAgent.OperationType动作类型。
requestCodenumber使用者定义的一个私有值。
wantAgentFlagsArray动作执行属性。
extraInfo{[key: string]: any}额外数据。

WantAgentFlags

系统能力 :以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

名称说明
ONE_TIME_FLAGWantAgentFlagsWantAgent仅能使用一次。
NO_BUILD_FLAGWantAgentFlags如果描述WantAgent对象不存在,则不创建它,直接返回null。
CANCEL_PRESENT_FLAGWantAgentFlags在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象。
UPDATE_PRESENT_FLAGWantAgentFlags使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据。
CONSTANT_FLAGWantAgentFlagsWantAgent是不可变的。
REPLACE_ELEMENTWantAgentFlags当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代
REPLACE_ACTIONWantAgentFlags当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代
REPLACE_URIWantAgentFlags当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代
REPLACE_ENTITIESWantAgentFlags当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代
REPLACE_BUNDLEWantAgentFlags当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代

OperationType

系统能力 :以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

名称说明
UNKNOWN_TYPEOperationType不识别的类型。
START_ABILITYOperationType开启一个有页面的Ability。
START_ABILITIESOperationType开启多个有页面的Ability。
START_SERVICEOperationType开启一个无页面的ability。
SEND_COMMON_EVENTOperationType发送一个公共事件。

CompleteData

系统能力 :以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

名称可读可写类型必填描述
infoWantAgent触发的wantAgent。
wantWant存在的被触发的want。
finalCodenumber触发wantAgent的请求代码。
finalDatastring公共事件收集的最终数据。
extraInfo{[key: string]: any}额外数据。
HarmonyOSOpenHarmony鸿蒙文档籽料:mau123789是v直接拿

搜狗高速浏览器截图20240326151450.png

TriggerInfo

系统能力 :以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

名称可读可写类型必填描述
codenumberresult code。
wantWantWant。
permissionstring权限定义。
extraInfo{[key: string]: any}额外数据。

审核编辑 黄宇

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 接口
    +关注

    关注

    33

    文章

    8595

    浏览量

    151142
  • 框架
    +关注

    关注

    0

    文章

    403

    浏览量

    17483
  • 鸿蒙
    +关注

    关注

    57

    文章

    2351

    浏览量

    42847
收藏 人收藏

    评论

    相关推荐

    鸿蒙开发接口Ability框架:【@ohos.application.Ability (Ability)】

    Ability模块提供对Ability生命周期、上下文环境等调用管理的能力,包括Ability创建、销毁、转储客户端信息等。
    的头像 发表于 04-30 17:42 2267次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【@<b class='flag-5'>ohos.application.Ability</b> (<b class='flag-5'>Ability</b>)】

    鸿蒙开发接口Ability框架:【@ohos.ability.featureAbility (FeatureAbility模块)】

    FeatureAbility模块提供带有UI设计与用户交互的能力,包括启动新的ability、获取dataAbilityHelper、设置此Page Ability、获取当前Ability
    的头像 发表于 05-06 16:31 1002次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【@<b class='flag-5'>ohos.ability</b>.featureAbility (FeatureAbility<b class='flag-5'>模块</b>)】

    鸿蒙开发接口Ability框架:【@ohos.application.FormExtension (FormExtension)】

    FormExtension模块提供了FormExtension卡片扩展相关接口
    的头像 发表于 05-07 09:43 733次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【@<b class='flag-5'>ohos</b>.application.FormExtension (FormExtension)】

    鸿蒙开发接口Ability框架:【@ohos.application.missionManager (missionManager)】

    表示Ability对应任务信息的枚举。
    的头像 发表于 05-08 09:19 900次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【@<b class='flag-5'>ohos</b>.application.missionManager (missionManager)】

    鸿蒙开发接口Ability框架:【@ohos.ability.particleAbility (particleAbility模块)】

    particleAbility模块提供了Service类型Ability的能力,包括启动、停止指定的particleAbility,获取dataAbilityHelper,连接、断开当前Ability与指定ServiceAbil
    的头像 发表于 05-09 10:21 718次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【@<b class='flag-5'>ohos.ability</b>.particleAbility (particleAbility<b class='flag-5'>模块</b>)】

    鸿蒙开发接口Ability框架:【 (Context模块)】

    Context模块提供了ability或application的上下文的能力,包括允许访问特定于应用程序的资源、请求和验证权限等。
    的头像 发表于 05-13 16:04 718次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【 (Context<b class='flag-5'>模块</b>)】

    鸿蒙开发接口Ability框架:【AbilityRunningInfo】

    AbilityRunningInfo模块提供对Ability运行的相关信息和状态进行设置和查询的能力。
    的头像 发表于 05-14 16:02 790次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【AbilityRunningInfo】

    鸿蒙开发接口Ability框架:【AbilityDelegator】

    AbilityDelegator提供添加用于监视指定能力的生命周期状态更改的AbilityMonitor对象的能力,包括对AbilityMonitor实例的添加、删除、等待ability到达
    的头像 发表于 05-16 16:48 934次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【AbilityDelegator】

    鸿蒙原生应用/元服务开发-通知添加行为意图

    开发步骤 1.导入模块。 import NotificationManager from \'@ohos.notificationManager\'; import wantAgent
    发表于 01-05 15:07

    鸿蒙原生应用/元服务开发-长时任务

    音乐,系统则会终止对应的进程。 接口说明:主要接口:代码开发:stage模型下 1.申请ohos.permission.KEEP_BACKGROUND_RUNNING权限,配置方式请参
    发表于 01-09 10:52

    HarmonyOS/OpenHarmony应用开发-ArkTS语言FA模型WantAgent使用

    from '@ohos.wantAgent';[]()[]()创建拉起Ability的WantAgentInfo信息,详细的WantAgentInfo信息数据类型及包含的参数请见
    发表于 01-17 15:06

    HarmonyOS位置服务开发指南

    有权限 ohos.permission.APPROXIMATELY_LOCATION,位置权限申请的方法和步骤见申请位置权限开发指导。 导入geoLocationManager模块wantA
    发表于 11-27 16:02

    鸿蒙之@ohos.app.ability.appRecovery (appRecovery)

    Ability的应用恢复。 导入模块 import appRecovery from ‘@ohos.app.ability.appRecovery’; appRecovery.RestartFlag
    的头像 发表于 02-20 16:28 447次阅读

    鸿蒙开发接口Ability框架:【AbilityRunningInfo】

    AbilityRunningInfo模块提供对Ability运行的相关信息和状态进行设置和查询的能力。
    的头像 发表于 05-17 17:12 325次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【AbilityRunningInfo】

    鸿蒙Ability Kit(程序框架服务)【Ability与ServiceExtensionAbility通信】

    本示例展示通过[IDL的方式]和 [@ohos.rpc] 等接口实现了Ability与ServiceExtensionAbility之间的通信。
    的头像 发表于 06-05 09:28 492次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>Ability</b> Kit(程序<b class='flag-5'>框架</b>服务)【<b class='flag-5'>Ability</b>与ServiceExtensionAbility通信】