0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

鴻蒙開發(fā)接口Ability框架:【@ohos.wantAgent (WantAgent模塊)】

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-05-13 17:35 ? 次閱讀

WantAgent模塊

WantAgent模塊提供了觸發(fā)、取消、比較WantAgent實例和獲取bundle名稱的能力,包括創(chuàng)建WantAgent實例、獲取實例的用戶ID、獲取want信息等。

說明:

本模塊首批接口從API version 7開始支持。后續(xù)版本的新增接口,采用上角標單獨標記接口的起始版本。

導入模塊

import WantAgent from '@ohos.wantAgent';

開發(fā)前請熟悉鴻蒙開發(fā)指導文檔:[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]

WantAgent.getWantAgent

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

創(chuàng)建WantAgent(callback形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù)

名稱可讀可寫類型必填描述
infoWantAgentInfoWantAgent信息。
callbackAsyncCallback創(chuàng)建WantAgent的回調(diào)方法。

示例:

import WantAgent from '@ohos.wantAgent';

//getWantAgent回調(diào)
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

創(chuàng)建WantAgent(Promise形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
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形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
agentWantAgentWantAgent對象。
callbackAsyncCallback獲取WantAgent實例的包名的回調(diào)方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent對象
var wantAgent;

//getWantAgent回調(diào)
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回調(diào)
function getBundleNameCallback(err, data) {
	console.info("========================== >getBundleNameCallback======================= >");
}
WantAgent.getBundleName(wantAgent, getBundleNameCallback)

WantAgent.getBundleName

getBundleName(agent: WantAgent): Promise

獲取WantAgent實例的包名(Promise形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
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形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
agentWantAgentWantAgent對象。
callbackAsyncCallback獲取WantAgent實例的用戶ID的回調(diào)方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent對象
var wantAgent;

//getWantAgent回調(diào)
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回調(diào)
function getUidCallback(err, data) {
	console.info("========================== >getUidCallback======================= >");
}
WantAgent.getUid(wantAgent, getUidCallback)

WantAgent.getUid

getUid(agent: WantAgent): Promise

獲取WantAgent實例的用戶ID(Promise形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
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形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

系統(tǒng)API : 此接口為系統(tǒng)接口,三方應(yīng)用不支持調(diào)用。

參數(shù):

名稱可讀可寫類型必填描述
agentWantAgentWantAgent對象。
callbackAsyncCallback獲取WantAgent對象want的回調(diào)方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent對象
var wantAgent;

//getWantAgent回調(diào)
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回調(diào)
function getWantCallback(err, data) {
	console.info("========================== >getWantCallback======================= >");
}
WantAgent.getWant(wantAgent, getWantCallback)

WantAgent.getWant

getWant(agent: WantAgent): Promise

獲取WantAgent對象的want(Promise形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

系統(tǒng)API : 此接口為系統(tǒng)接口,三方應(yīng)用不支持調(diào)用。

參數(shù):

名稱可讀可寫類型必填描述
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形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
agentWantAgentWantAgent對象。
callbackAsyncCallback取消WantAgent實例的回調(diào)方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent對象
var wantAgent;

//getWantAgent回調(diào)
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回調(diào)
function cancelCallback(err, data) {
	console.info("========================== >cancelCallback======================= >");
}
WantAgent.cancel(wantAgent, cancelCallback)

WantAgent.cancel

cancel(agent: WantAgent): Promise

取消WantAgent實例(Promise形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
agentWantAgentWantAgent對象。

返回值:

類型說明
Promise以Promise形式獲取異步返回結(jié)果。

示例:

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

主動激發(fā)WantAgent實例(callback形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
agentWantAgentWantAgent對象。
triggerInfoTriggerInfoTriggerInfo對象。
callbackAsyncCallback主動激發(fā)WantAgent實例的回調(diào)方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent對象
var wantAgent;

//getWantAgent回調(diào)
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回調(diào)
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形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
agentWantAgentWantAgent對象。
otherAgentWantAgentWantAgent對象。
callbackAsyncCallback判斷兩個WantAgent實例是否相等的回調(diào)方法。

示例:

import WantAgent from '@ohos.wantAgent';


//wantAgent對象
var wantAgent1;
var wantAgent2;

//getWantAgent回調(diào)
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回調(diào)
function equalCallback(err, data) {
	console.info("========================== >equalCallback======================= >");
}
WantAgent.equal(wantAgent1, wantAgent2, equalCallback)

WantAgent.equal

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

判斷兩個WantAgent實例是否相等(Promise形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
agentWantAgentWantAgent對象。
otherAgentWantAgentWantAgent對象。

返回值:

類型說明
Promise以Promise形式返回獲取判斷兩個WantAgent實例是否相等的結(jié)果。

示例:

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形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
agentWantAgentWantAgent對象。
callbackAsyncCallback獲取一個WantAgent的OperationType信息的回調(diào)方法。

示例:

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形式)。

系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core

參數(shù):

名稱可讀可寫類型必填描述
agentWantAgentWantAgent對象。

返回值:

類型說明
Promise以Promise形式返回獲取optionType的結(jié)果。

示例:

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

系統(tǒng)能力 :以下各項對應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core

名稱可讀可寫類型必填描述
wantsArray將被執(zhí)行的動作列表。
operationTypewantAgent.OperationType動作類型。
requestCodenumber使用者定義的一個私有值。
wantAgentFlagsArray動作執(zhí)行屬性。
extraInfo{[key: string]: any}額外數(shù)據(jù)。

WantAgentFlags

系統(tǒng)能力 :以下各項對應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core

名稱說明
ONE_TIME_FLAGWantAgentFlagsWantAgent僅能使用一次。
NO_BUILD_FLAGWantAgentFlags如果描述WantAgent對象不存在,則不創(chuàng)建它,直接返回null。
CANCEL_PRESENT_FLAGWantAgentFlags在生成一個新的WantAgent對象前取消已存在的一個WantAgent對象。
UPDATE_PRESENT_FLAGWantAgentFlags使用新的WantAgent的額外數(shù)據(jù)替換已存在的WantAgent中的額外數(shù)據(jù)。
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

系統(tǒng)能力 :以下各項對應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core

名稱說明
UNKNOWN_TYPEOperationType不識別的類型。
START_ABILITYOperationType開啟一個有頁面的Ability。
START_ABILITIESOperationType開啟多個有頁面的Ability。
START_SERVICEOperationType開啟一個無頁面的ability。
SEND_COMMON_EVENTOperationType發(fā)送一個公共事件。

CompleteData

系統(tǒng)能力 :以下各項對應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core

名稱可讀可寫類型必填描述
infoWantAgent觸發(fā)的wantAgent。
wantWant存在的被觸發(fā)的want。
finalCodenumber觸發(fā)wantAgent的請求代碼。
finalDatastring公共事件收集的最終數(shù)據(jù)。
extraInfo{[key: string]: any}額外數(shù)據(jù)。
HarmonyOSOpenHarmony鴻蒙文檔籽料:mau123789是v直接拿

搜狗高速瀏覽器截圖20240326151450.png

TriggerInfo

系統(tǒng)能力 :以下各項對應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core

名稱可讀可寫類型必填描述
codenumberresult code。
wantWantWant。
permissionstring權(quán)限定義。
extraInfo{[key: string]: any}額外數(shù)據(jù)。

審核編輯 黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 接口
    +關(guān)注

    關(guān)注

    33

    文章

    8447

    瀏覽量

    150720
  • 框架
    +關(guān)注

    關(guān)注

    0

    文章

    398

    瀏覽量

    17404
  • 鴻蒙
    +關(guān)注

    關(guān)注

    57

    文章

    2302

    瀏覽量

    42689
收藏 人收藏

    評論

    相關(guān)推薦

    鴻蒙開發(fā)接口Ability框架:【@ohos.application.Ability (Ability)】

    Ability模塊提供對Ability生命周期、上下文環(huán)境等調(diào)用管理的能力,包括Ability創(chuàng)建、銷毀、轉(zhuǎn)儲客戶端信息等。
    的頭像 發(fā)表于 04-30 17:42 ?2184次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</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>)】

    鴻蒙開發(fā)接口Ability框架:【@ohos.ability.featureAbility (FeatureAbility模塊)】

    FeatureAbility模塊提供帶有UI設(shè)計與用戶交互的能力,包括啟動新的ability、獲取dataAbilityHelper、設(shè)置此Page Ability、獲取當前Ability
    的頭像 發(fā)表于 05-06 16:31 ?904次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</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>)】

    鴻蒙開發(fā)接口Ability框架:【@ohos.application.FormExtension (FormExtension)】

    FormExtension模塊提供了FormExtension卡片擴展相關(guān)接口。
    的頭像 發(fā)表于 05-07 09:43 ?681次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</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)】

    鴻蒙開發(fā)接口Ability框架:【@ohos.application.missionManager (missionManager)】

    表示Ability對應(yīng)任務(wù)信息的枚舉。
    的頭像 發(fā)表于 05-08 09:19 ?848次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</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)】

    鴻蒙開發(fā)接口Ability框架:【@ohos.ability.particleAbility (particleAbility模塊)】

    particleAbility模塊提供了Service類型Ability的能力,包括啟動、停止指定的particleAbility,獲取dataAbilityHelper,連接、斷開當前Ability與指定ServiceAbil
    的頭像 發(fā)表于 05-09 10:21 ?660次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</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>)】

    鴻蒙開發(fā)接口Ability框架:【 (Context模塊)】

    Context模塊提供了ability或application的上下文的能力,包括允許訪問特定于應(yīng)用程序的資源、請求和驗證權(quán)限等。
    的頭像 發(fā)表于 05-13 16:04 ?653次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【 (Context<b class='flag-5'>模塊</b>)】

    鴻蒙開發(fā)接口Ability框架:【AbilityRunningInfo】

    AbilityRunningInfo模塊提供對Ability運行的相關(guān)信息和狀態(tài)進行設(shè)置和查詢的能力。
    的頭像 發(fā)表于 05-14 16:02 ?740次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【AbilityRunningInfo】

    鴻蒙開發(fā)接口Ability框架:【AbilityDelegator】

    AbilityDelegator提供添加用于監(jiān)視指定能力的生命周期狀態(tài)更改的AbilityMonitor對象的能力,包括對AbilityMonitor實例的添加、刪除、等待ability到達
    的頭像 發(fā)表于 05-16 16:48 ?890次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【AbilityDelegator】

    鴻蒙原生應(yīng)用/元服務(wù)開發(fā)-通知添加行為意圖

    開發(fā)步驟 1.導入模塊。 import NotificationManager from \'@ohos.notificationManager\'; import wantAgent
    發(fā)表于 01-05 15:07

    鴻蒙原生應(yīng)用/元服務(wù)開發(fā)-長時任務(wù)

    音樂,系統(tǒng)則會終止對應(yīng)的進程。 接口說明:主要接口:代碼開發(fā):stage模型下 1.申請ohos.permission.KEEP_BACKGROUND_RUNNING權(quán)限,配置方式請參
    發(fā)表于 01-09 10:52

    HarmonyOS/OpenHarmony應(yīng)用開發(fā)-ArkTS語言FA模型WantAgent使用

    from '@ohos.wantAgent';[]()[]()創(chuàng)建拉起Ability的WantAgentInfo信息,詳細的WantAgentInfo信息數(shù)據(jù)類型及包含的參數(shù)請見
    發(fā)表于 01-17 15:06

    HarmonyOS位置服務(wù)開發(fā)指南

    有權(quán)限 ohos.permission.APPROXIMATELY_LOCATION,位置權(quán)限申請的方法和步驟見申請位置權(quán)限開發(fā)指導。 導入geoLocationManager模塊wantA
    發(fā)表于 11-27 16:02

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

    Ability的應(yīng)用恢復。 導入模塊 import appRecovery from ‘@ohos.app.ability.appRecovery’; appRecovery.RestartFlag
    的頭像 發(fā)表于 02-20 16:28 ?408次閱讀

    鴻蒙開發(fā)接口Ability框架:【AbilityRunningInfo】

    AbilityRunningInfo模塊提供對Ability運行的相關(guān)信息和狀態(tài)進行設(shè)置和查詢的能力。
    的頭像 發(fā)表于 05-17 17:12 ?280次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b><b class='flag-5'>接口</b><b class='flag-5'>Ability</b><b class='flag-5'>框架</b>:【AbilityRunningInfo】

    鴻蒙Ability Kit(程序框架服務(wù))【Ability與ServiceExtensionAbility通信】

    本示例展示通過[IDL的方式]和?[@ohos.rpc]?等接口實現(xiàn)了Ability與ServiceExtensionAbility之間的通信。
    的頭像 發(fā)表于 06-05 09:28 ?435次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>Ability</b> Kit(程序<b class='flag-5'>框架</b>服務(wù))【<b class='flag-5'>Ability</b>與ServiceExtensionAbility通信】