W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
WantAgent模塊提供了觸發(fā)、取消、比較WantAgent實(shí)例和獲取bundle名稱的能力,包括創(chuàng)建WantAgent實(shí)例、獲取實(shí)例的用戶ID、獲取want信息等。
本模塊首批接口從API version 9開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。
getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>): void
創(chuàng)建WantAgent(callback形式)。 創(chuàng)建失敗返回的WantAgent為空值。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
info | 是 | WantAgent信息。 | |
callback | AsyncCallback<WantAgent> | 是 | 創(chuàng)建WantAgent的回調(diào)方法。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //getWantAgent回調(diào)
- function getWantAgentCallback(err, data) {
- console.info('==========================>getWantAgentCallback=======================>');
- }
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
getWantAgent(info: WantAgentInfo): Promise<WantAgent>
創(chuàng)建WantAgent(Promise形式)。 創(chuàng)建失敗返回的WantAgent為空值。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
info | 是 | WantAgent信息。 |
返回值:
類型 | 說明 |
---|---|
Promise<WantAgent> | 以Promise形式返回WantAgent。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo).then((data) => {
- console.info('==========================>getWantAgentCallback=======================>');
- });
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
getBundleName(agent: WantAgent, callback: AsyncCallback<string>): void
獲取WantAgent實(shí)例的包名(callback形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
callback | AsyncCallback<string> | 是 | 獲取WantAgent實(shí)例的包名的回調(diào)方法。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent;
- //getWantAgent回調(diào)
- function getWantAgentCallback(err, data) {
- console.info('==========================>getWantAgentCallback=======================>');
- if (err.code == 0) {
- wantAgent = data;
- } else {
- console.info('----getWantAgent failed!----');
- }
- }
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
- //getBundleName回調(diào)
- function getBundleNameCallback(err, data) {
- console.info('==========================>getBundleNameCallback=======================>');
- }
- WantAgent.getBundleName(wantAgent, getBundleNameCallback);
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
getBundleName(agent: WantAgent): Promise<string>
獲取WantAgent實(shí)例的包名(Promise形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | 以Promise形式返回獲取WantAgent實(shí)例的包名。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent;
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo).then((data) => {
- console.info('==========================>getWantAgentCallback=======================>');
- wantAgent = data;
- });
- WantAgent.getBundleName(wantAgent).then((data) => {
- console.info('==========================>getBundleNameCallback=======================>');
- });
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
getUid(agent: WantAgent, callback: AsyncCallback<number>): void
獲取WantAgent實(shí)例的用戶ID(callback形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
callback | AsyncCallback<number> | 是 | 獲取WantAgent實(shí)例的用戶ID的回調(diào)方法。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent;
- //getWantAgent回調(diào)
- function getWantAgentCallback(err, data) {
- console.info('==========================>getWantAgentCallback=======================>');
- if (err.code == 0) {
- wantAgent = data;
- } else {
- console.info('----getWantAgent failed!----');
- }
- }
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
- //getUid回調(diào)
- function getUidCallback(err, data) {
- console.info('==========================>getUidCallback=======================>');
- }
- WantAgent.getUid(wantAgent, getUidCallback);
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
getUid(agent: WantAgent): Promise<number>
獲取WantAgent實(shí)例的用戶ID(Promise形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
返回值:
類型 | 說明 |
---|---|
Promise<number> | 以Promise形式返回獲取WantAgent實(shí)例的用戶ID。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent;
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo).then((data) => {
- console.info('==========================>getWantAgentCallback=======================>');
- wantAgent = data;
- });
- WantAgent.getUid(wantAgent).then((data) => {
- console.info('==========================>getUidCallback=======================>');
- });
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
cancel(agent: WantAgent, callback: AsyncCallback<void>): void
取消WantAgent實(shí)例(callback形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
callback | AsyncCallback<void> | 是 | 取消WantAgent實(shí)例的回調(diào)方法。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent;
- //getWantAgent回調(diào)
- function getWantAgentCallback(err, data) {
- console.info('==========================>getWantAgentCallback=======================>');
- if (err.code == 0) {
- wantAgent = data;
- } else {
- console.info('----getWantAgent failed!----');
- }
- }
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
- //cancel回調(diào)
- function cancelCallback(err, data) {
- console.info('==========================>cancelCallback=======================>');
- }
- WantAgent.cancel(wantAgent, cancelCallback);
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
cancel(agent: WantAgent): Promise<void>
取消WantAgent實(shí)例(Promise形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 以Promise形式獲取異步返回結(jié)果。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent;
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo).then((data) => {
- console.info('==========================>getWantAgentCallback=======================>');
- wantAgent = data;
- });
- WantAgent.cancel(wantAgent).then((data) => {
- console.info('==========================>cancelCallback=======================>');
- });
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback<CompleteData>): void
主動(dòng)激發(fā)WantAgent實(shí)例(callback形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
triggerInfo | TriggerInfo | 是 | TriggerInfo對(duì)象。 |
callback | AsyncCallback<CompleteData> | 否 | 主動(dòng)激發(fā)WantAgent實(shí)例的回調(diào)方法。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent;
- //getWantAgent回調(diào)
- function getWantAgentCallback(err, data) {
- console.info('==========================>getWantAgentCallback=======================>');
- if (err.code == 0) {
- wantAgent = data;
- } else {
- console.info('----getWantAgent failed!----');
- }
- }
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
- //trigger回調(diào)
- function triggerCallback(data) {
- console.info('==========================>triggerCallback=======================>');
- }
- let triggerInfo = {
- code:0
- };
- WantAgent.trigger(wantAgent, triggerInfo, triggerCallback);
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>): void
判斷兩個(gè)WantAgent實(shí)例是否相等(callback形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
otherAgent | WantAgent | 是 | WantAgent對(duì)象。 |
callback | AsyncCallback<boolean> | 是 | 判斷兩個(gè)WantAgent實(shí)例是否相等的回調(diào)方法。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent1;
- let 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對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
- //equal回調(diào)
- function equalCallback(err, data) {
- console.info('==========================>equalCallback=======================>');
- }
- WantAgent.equal(wantAgent1, wantAgent2, equalCallback);
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
equal(agent: WantAgent, otherAgent: WantAgent): Promise<boolean>
判斷兩個(gè)WantAgent實(shí)例是否相等(Promise形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
otherAgent | WantAgent | 是 | WantAgent對(duì)象。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | 以Promise形式返回獲取判斷兩個(gè)WantAgent實(shí)例是否相等的結(jié)果。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent1;
- let wantAgent2;
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo).then((data) => {
- console.info('==========================>getWantAgentCallback=======================>');
- wantAgent1 = data;
- wantAgent2 = data;
- });
- WantAgent.equal(wantAgent1, wantAgent2).then((data) => {
- console.info('==========================>equalCallback=======================>');
- });
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
getOperationType(agent: WantAgent, callback: AsyncCallback<number>): void;
獲取一個(gè)WantAgent的OperationType信息(callback形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
callback | AsyncCallback<number> | 是 | 獲取一個(gè)WantAgent的OperationType信息的回調(diào)方法。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent;
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- WantAgent.getWantAgent(wantAgentInfo).then((data) => {
- console.info('==========================>getWantAgentCallback=======================>');
- wantAgent = data;
- });
- WantAgent.getOperationType(wantAgent, (OperationType) => {
- console.log('----------- getOperationType ----------, OperationType: ' + OperationType);
- })
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
getOperationType(agent: WantAgent): Promise<number>;
獲取一個(gè)WantAgent的OperationType信息(Promise形式)。
系統(tǒng)能力:SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
agent | WantAgent | 是 | WantAgent對(duì)象。 |
返回值:
類型 | 說明 |
---|---|
Promise<number> | 以Promise形式返回獲取operationType的結(jié)果。 |
示例:
- import WantAgent from '@ohos.app.ability.wantAgent';
- //wantAgent對(duì)象
- let wantAgent;
- //WantAgentInfo對(duì)象
- let 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]
- };
- try {
- 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);
- })
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
系統(tǒng)能力:以下各項(xiàng)對(duì)應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core
名稱 | 值 | 說明 |
---|---|---|
ONE_TIME_FLAG | 0 | WantAgent僅能使用一次。 |
NO_BUILD_FLAG | 1 | 如果描述WantAgent對(duì)象不存在,則不創(chuàng)建它,直接返回null。 |
CANCEL_PRESENT_FLAG | 2 | 在生成一個(gè)新的WantAgent對(duì)象前取消已存在的一個(gè)WantAgent對(duì)象。 |
UPDATE_PRESENT_FLAG | 3 | 使用新的WantAgent的額外數(shù)據(jù)替換已存在的WantAgent中的額外數(shù)據(jù)。 |
CONSTANT_FLAG | 4 | WantAgent是不可變的。 |
REPLACE_ELEMENT | 5 | 當(dāng)前Want中的element屬性可被WantAgent.trigger()中Want的element屬性取代 |
REPLACE_ACTION | 6 | 當(dāng)前Want中的action屬性可被WantAgent.trigger()中Want的action屬性取代 |
REPLACE_URI | 7 | 當(dāng)前Want中的uri屬性可被WantAgent.trigger()中Want的uri屬性取代 |
REPLACE_ENTITIES | 8 | 當(dāng)前Want中的entities屬性可被WantAgent.trigger()中Want的entities屬性取代 |
REPLACE_BUNDLE | 9 | 當(dāng)前Want中的bundleName屬性可被WantAgent.trigger()中Want的bundleName屬性取代 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: