觸發(fā)、取消、比較WantAgent實(shí)例和獲取bundle名稱的能力

2024-01-23 12:51 更新

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

說明

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

導(dǎo)入模塊

  1. import WantAgent from '@ohos.app.ability.wantAgent';

WantAgent.getWantAgent

getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>): void

創(chuàng)建WantAgent(callback形式)。 創(chuàng)建失敗返回的WantAgent為空值。

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

參數(shù):

參數(shù)名

類型

必填

說明

info

WantAgentInfo

WantAgent信息。

callback

AsyncCallback<WantAgent>

創(chuàng)建WantAgent的回調(diào)方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //getWantAgent回調(diào)
  3. function getWantAgentCallback(err, data) {
  4. console.info('==========================>getWantAgentCallback=======================>');
  5. }
  6. //WantAgentInfo對(duì)象
  7. let wantAgentInfo = {
  8. wants: [
  9. {
  10. deviceId: 'deviceId',
  11. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  12. abilityName: 'com.example.test.MainAbility',
  13. action: 'action1',
  14. entities: ['entity1'],
  15. type: 'MIMETYPE',
  16. uri: 'key={true,true,false}',
  17. parameters:
  18. {
  19. mykey0: 2222,
  20. mykey1: [1, 2, 3],
  21. mykey2: '[1, 2, 3]',
  22. mykey3: 'ssssssssssssssssssssssssss',
  23. mykey4: [false, true, false],
  24. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  25. mykey6: true,
  26. }
  27. }
  28. ],
  29. operationType: WantAgent.OperationType.START_ABILITIES,
  30. requestCode: 0,
  31. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  32. };
  33. try {
  34. WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
  35. } catch (paramError) {
  36. console.log('error: ' + paramError.code + ', ' + paramError.message);
  37. }

WantAgent.getWantAgent

getWantAgent(info: WantAgentInfo): Promise<WantAgent>

創(chuàng)建WantAgent(Promise形式)。 創(chuàng)建失敗返回的WantAgent為空值。

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

參數(shù):

參數(shù)名

類型

必填

說明

info

WantAgentInfo

WantAgent信息。

返回值:

類型

說明

Promise<WantAgent>

以Promise形式返回WantAgent。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //WantAgentInfo對(duì)象
  3. let wantAgentInfo = {
  4. wants: [
  5. {
  6. deviceId: 'deviceId',
  7. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  8. abilityName: 'com.example.test.MainAbility',
  9. action: 'action1',
  10. entities: ['entity1'],
  11. type: 'MIMETYPE',
  12. uri: 'key={true,true,false}',
  13. parameters:
  14. {
  15. mykey0: 2222,
  16. mykey1: [1, 2, 3],
  17. mykey2: '[1, 2, 3]',
  18. mykey3: 'ssssssssssssssssssssssssss',
  19. mykey4: [false, true, false],
  20. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  21. mykey6: true,
  22. }
  23. }
  24. ],
  25. operationType: WantAgent.OperationType.START_ABILITIES,
  26. requestCode: 0,
  27. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  28. };
  29. try {
  30. WantAgent.getWantAgent(wantAgentInfo).then((data) => {
  31. console.info('==========================>getWantAgentCallback=======================>');
  32. });
  33. } catch (paramError) {
  34. console.log('error: ' + paramError.code + ', ' + paramError.message);
  35. }

WantAgent.getBundleName

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)方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent;
  4. //getWantAgent回調(diào)
  5. function getWantAgentCallback(err, data) {
  6. console.info('==========================>getWantAgentCallback=======================>');
  7. if (err.code == 0) {
  8. wantAgent = data;
  9. } else {
  10. console.info('----getWantAgent failed!----');
  11. }
  12. }
  13. //WantAgentInfo對(duì)象
  14. let wantAgentInfo = {
  15. wants: [
  16. {
  17. deviceId: 'deviceId',
  18. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  19. abilityName: 'com.example.test.MainAbility',
  20. action: 'action1',
  21. entities: ['entity1'],
  22. type: 'MIMETYPE',
  23. uri: 'key={true,true,false}',
  24. parameters:
  25. {
  26. mykey0: 2222,
  27. mykey1: [1, 2, 3],
  28. mykey2: '[1, 2, 3]',
  29. mykey3: 'ssssssssssssssssssssssssss',
  30. mykey4: [false, true, false],
  31. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  32. mykey6: true,
  33. }
  34. }
  35. ],
  36. operationType: WantAgent.OperationType.START_ABILITIES,
  37. requestCode: 0,
  38. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  39. };
  40. try {
  41. WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
  42. //getBundleName回調(diào)
  43. function getBundleNameCallback(err, data) {
  44. console.info('==========================>getBundleNameCallback=======================>');
  45. }
  46. WantAgent.getBundleName(wantAgent, getBundleNameCallback);
  47. } catch (paramError) {
  48. console.log('error: ' + paramError.code + ', ' + paramError.message);
  49. }

WantAgent.getBundleName

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í)例的包名。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent;
  4. //WantAgentInfo對(duì)象
  5. let wantAgentInfo = {
  6. wants: [
  7. {
  8. deviceId: 'deviceId',
  9. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  10. abilityName: 'com.example.test.MainAbility',
  11. action: 'action1',
  12. entities: ['entity1'],
  13. type: 'MIMETYPE',
  14. uri: 'key={true,true,false}',
  15. parameters:
  16. {
  17. mykey0: 2222,
  18. mykey1: [1, 2, 3],
  19. mykey2: '[1, 2, 3]',
  20. mykey3: 'ssssssssssssssssssssssssss',
  21. mykey4: [false, true, false],
  22. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  23. mykey6: true,
  24. }
  25. }
  26. ],
  27. operationType: WantAgent.OperationType.START_ABILITIES,
  28. requestCode: 0,
  29. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  30. };
  31. try {
  32. WantAgent.getWantAgent(wantAgentInfo).then((data) => {
  33. console.info('==========================>getWantAgentCallback=======================>');
  34. wantAgent = data;
  35. });
  36. WantAgent.getBundleName(wantAgent).then((data) => {
  37. console.info('==========================>getBundleNameCallback=======================>');
  38. });
  39. } catch (paramError) {
  40. console.log('error: ' + paramError.code + ', ' + paramError.message);
  41. }

WantAgent.getUid

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)方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent;
  4. //getWantAgent回調(diào)
  5. function getWantAgentCallback(err, data) {
  6. console.info('==========================>getWantAgentCallback=======================>');
  7. if (err.code == 0) {
  8. wantAgent = data;
  9. } else {
  10. console.info('----getWantAgent failed!----');
  11. }
  12. }
  13. //WantAgentInfo對(duì)象
  14. let wantAgentInfo = {
  15. wants: [
  16. {
  17. deviceId: 'deviceId',
  18. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  19. abilityName: 'com.example.test.MainAbility',
  20. action: 'action1',
  21. entities: ['entity1'],
  22. type: 'MIMETYPE',
  23. uri: 'key={true,true,false}',
  24. parameters:
  25. {
  26. mykey0: 2222,
  27. mykey1: [1, 2, 3],
  28. mykey2: '[1, 2, 3]',
  29. mykey3: 'ssssssssssssssssssssssssss',
  30. mykey4: [false, true, false],
  31. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  32. mykey6: true,
  33. }
  34. }
  35. ],
  36. operationType: WantAgent.OperationType.START_ABILITIES,
  37. requestCode: 0,
  38. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  39. };
  40. try {
  41. WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
  42. //getUid回調(diào)
  43. function getUidCallback(err, data) {
  44. console.info('==========================>getUidCallback=======================>');
  45. }
  46. WantAgent.getUid(wantAgent, getUidCallback);
  47. } catch (paramError) {
  48. console.log('error: ' + paramError.code + ', ' + paramError.message);
  49. }

WantAgent.getUid

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。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent;
  4. //WantAgentInfo對(duì)象
  5. let wantAgentInfo = {
  6. wants: [
  7. {
  8. deviceId: 'deviceId',
  9. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  10. abilityName: 'com.example.test.MainAbility',
  11. action: 'action1',
  12. entities: ['entity1'],
  13. type: 'MIMETYPE',
  14. uri: 'key={true,true,false}',
  15. parameters:
  16. {
  17. mykey0: 2222,
  18. mykey1: [1, 2, 3],
  19. mykey2: '[1, 2, 3]',
  20. mykey3: 'ssssssssssssssssssssssssss',
  21. mykey4: [false, true, false],
  22. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  23. mykey6: true,
  24. }
  25. }
  26. ],
  27. operationType: WantAgent.OperationType.START_ABILITIES,
  28. requestCode: 0,
  29. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  30. };
  31. try {
  32. WantAgent.getWantAgent(wantAgentInfo).then((data) => {
  33. console.info('==========================>getWantAgentCallback=======================>');
  34. wantAgent = data;
  35. });
  36. WantAgent.getUid(wantAgent).then((data) => {
  37. console.info('==========================>getUidCallback=======================>');
  38. });
  39. } catch (paramError) {
  40. console.log('error: ' + paramError.code + ', ' + paramError.message);
  41. }

WantAgent.cancel

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)方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent;
  4. //getWantAgent回調(diào)
  5. function getWantAgentCallback(err, data) {
  6. console.info('==========================>getWantAgentCallback=======================>');
  7. if (err.code == 0) {
  8. wantAgent = data;
  9. } else {
  10. console.info('----getWantAgent failed!----');
  11. }
  12. }
  13. //WantAgentInfo對(duì)象
  14. let wantAgentInfo = {
  15. wants: [
  16. {
  17. deviceId: 'deviceId',
  18. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  19. abilityName: 'com.example.test.MainAbility',
  20. action: 'action1',
  21. entities: ['entity1'],
  22. type: 'MIMETYPE',
  23. uri: 'key={true,true,false}',
  24. parameters:
  25. {
  26. mykey0: 2222,
  27. mykey1: [1, 2, 3],
  28. mykey2: '[1, 2, 3]',
  29. mykey3: 'ssssssssssssssssssssssssss',
  30. mykey4: [false, true, false],
  31. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  32. mykey6: true,
  33. }
  34. }
  35. ],
  36. operationType: WantAgent.OperationType.START_ABILITIES,
  37. requestCode: 0,
  38. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  39. };
  40. try {
  41. WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
  42. //cancel回調(diào)
  43. function cancelCallback(err, data) {
  44. console.info('==========================>cancelCallback=======================>');
  45. }
  46. WantAgent.cancel(wantAgent, cancelCallback);
  47. } catch (paramError) {
  48. console.log('error: ' + paramError.code + ', ' + paramError.message);
  49. }

WantAgent.cancel

cancel(agent: WantAgent): Promise<void>

取消WantAgent實(shí)例(Promise形式)。

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

參數(shù):

參數(shù)名

類型

必填

說明

agent

WantAgent

WantAgent對(duì)象。

返回值:

類型

說明

Promise<void>

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

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent;
  4. //WantAgentInfo對(duì)象
  5. let wantAgentInfo = {
  6. wants: [
  7. {
  8. deviceId: 'deviceId',
  9. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  10. abilityName: 'com.example.test.MainAbility',
  11. action: 'action1',
  12. entities: ['entity1'],
  13. type: 'MIMETYPE',
  14. uri: 'key={true,true,false}',
  15. parameters:
  16. {
  17. mykey0: 2222,
  18. mykey1: [1, 2, 3],
  19. mykey2: '[1, 2, 3]',
  20. mykey3: 'ssssssssssssssssssssssssss',
  21. mykey4: [false, true, false],
  22. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  23. mykey6: true,
  24. }
  25. }
  26. ],
  27. operationType: WantAgent.OperationType.START_ABILITIES,
  28. requestCode: 0,
  29. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  30. };
  31. try {
  32. WantAgent.getWantAgent(wantAgentInfo).then((data) => {
  33. console.info('==========================>getWantAgentCallback=======================>');
  34. wantAgent = data;
  35. });
  36. WantAgent.cancel(wantAgent).then((data) => {
  37. console.info('==========================>cancelCallback=======================>');
  38. });
  39. } catch (paramError) {
  40. console.log('error: ' + paramError.code + ', ' + paramError.message);
  41. }

WantAgent.trigger

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)方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent;
  4. //getWantAgent回調(diào)
  5. function getWantAgentCallback(err, data) {
  6. console.info('==========================>getWantAgentCallback=======================>');
  7. if (err.code == 0) {
  8. wantAgent = data;
  9. } else {
  10. console.info('----getWantAgent failed!----');
  11. }
  12. }
  13. //WantAgentInfo對(duì)象
  14. let wantAgentInfo = {
  15. wants: [
  16. {
  17. deviceId: 'deviceId',
  18. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  19. abilityName: 'com.example.test.MainAbility',
  20. action: 'action1',
  21. entities: ['entity1'],
  22. type: 'MIMETYPE',
  23. uri: 'key={true,true,false}',
  24. parameters:
  25. {
  26. mykey0: 2222,
  27. mykey1: [1, 2, 3],
  28. mykey2: '[1, 2, 3]',
  29. mykey3: 'ssssssssssssssssssssssssss',
  30. mykey4: [false, true, false],
  31. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  32. mykey6: true,
  33. }
  34. }
  35. ],
  36. operationType: WantAgent.OperationType.START_ABILITIES,
  37. requestCode: 0,
  38. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  39. };
  40. try {
  41. WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
  42. //trigger回調(diào)
  43. function triggerCallback(data) {
  44. console.info('==========================>triggerCallback=======================>');
  45. }
  46. let triggerInfo = {
  47. code:0
  48. };
  49. WantAgent.trigger(wantAgent, triggerInfo, triggerCallback);
  50. } catch (paramError) {
  51. console.log('error: ' + paramError.code + ', ' + paramError.message);
  52. }

WantAgent.equal

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)方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent1;
  4. let wantAgent2;
  5. //getWantAgent回調(diào)
  6. function getWantAgentCallback(err, data) {
  7. console.info('==========================>getWantAgentCallback=======================>');
  8. if (err.code == 0) {
  9. wantAgent1 = data;
  10. wantAgent2 = data;
  11. } else {
  12. console.info('----getWantAgent failed!----');
  13. }
  14. }
  15. //WantAgentInfo對(duì)象
  16. let wantAgentInfo = {
  17. wants: [
  18. {
  19. deviceId: 'deviceId',
  20. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  21. abilityName: 'com.example.test.MainAbility',
  22. action: 'action1',
  23. entities: ['entity1'],
  24. type: 'MIMETYPE',
  25. uri: 'key={true,true,false}',
  26. parameters:
  27. {
  28. mykey0: 2222,
  29. mykey1: [1, 2, 3],
  30. mykey2: '[1, 2, 3]',
  31. mykey3: 'ssssssssssssssssssssssssss',
  32. mykey4: [false, true, false],
  33. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  34. mykey6: true,
  35. }
  36. }
  37. ],
  38. operationType: WantAgent.OperationType.START_ABILITIES,
  39. requestCode: 0,
  40. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  41. };
  42. try {
  43. WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
  44. //equal回調(diào)
  45. function equalCallback(err, data) {
  46. console.info('==========================>equalCallback=======================>');
  47. }
  48. WantAgent.equal(wantAgent1, wantAgent2, equalCallback);
  49. } catch (paramError) {
  50. console.log('error: ' + paramError.code + ', ' + paramError.message);
  51. }

WantAgent.equal

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é)果。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent1;
  4. let wantAgent2;
  5. //WantAgentInfo對(duì)象
  6. let wantAgentInfo = {
  7. wants: [
  8. {
  9. deviceId: 'deviceId',
  10. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  11. abilityName: 'com.example.test.MainAbility',
  12. action: 'action1',
  13. entities: ['entity1'],
  14. type: 'MIMETYPE',
  15. uri: 'key={true,true,false}',
  16. parameters:
  17. {
  18. mykey0: 2222,
  19. mykey1: [1, 2, 3],
  20. mykey2: '[1, 2, 3]',
  21. mykey3: 'ssssssssssssssssssssssssss',
  22. mykey4: [false, true, false],
  23. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  24. mykey6: true,
  25. }
  26. }
  27. ],
  28. operationType: WantAgent.OperationType.START_ABILITIES,
  29. requestCode: 0,
  30. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  31. };
  32. try {
  33. WantAgent.getWantAgent(wantAgentInfo).then((data) => {
  34. console.info('==========================>getWantAgentCallback=======================>');
  35. wantAgent1 = data;
  36. wantAgent2 = data;
  37. });
  38. WantAgent.equal(wantAgent1, wantAgent2).then((data) => {
  39. console.info('==========================>equalCallback=======================>');
  40. });
  41. } catch (paramError) {
  42. console.log('error: ' + paramError.code + ', ' + paramError.message);
  43. }

WantAgent.getOperationType

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)方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent;
  4. //WantAgentInfo對(duì)象
  5. let wantAgentInfo = {
  6. wants: [
  7. {
  8. deviceId: 'deviceId',
  9. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  10. abilityName: 'com.example.test.MainAbility',
  11. action: 'action1',
  12. entities: ['entity1'],
  13. type: 'MIMETYPE',
  14. uri: 'key={true,true,false}',
  15. parameters:
  16. {
  17. mykey0: 2222,
  18. mykey1: [1, 2, 3],
  19. mykey2: '[1, 2, 3]',
  20. mykey3: 'ssssssssssssssssssssssssss',
  21. mykey4: [false, true, false],
  22. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  23. mykey6: true,
  24. }
  25. }
  26. ],
  27. operationType: WantAgent.OperationType.START_ABILITIES,
  28. requestCode: 0,
  29. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  30. };
  31. try {
  32. WantAgent.getWantAgent(wantAgentInfo).then((data) => {
  33. console.info('==========================>getWantAgentCallback=======================>');
  34. wantAgent = data;
  35. });
  36. WantAgent.getOperationType(wantAgent, (OperationType) => {
  37. console.log('----------- getOperationType ----------, OperationType: ' + OperationType);
  38. })
  39. } catch (paramError) {
  40. console.log('error: ' + paramError.code + ', ' + paramError.message);
  41. }

WantAgent.getOperationType

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é)果。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent對(duì)象
  3. let wantAgent;
  4. //WantAgentInfo對(duì)象
  5. let wantAgentInfo = {
  6. wants: [
  7. {
  8. deviceId: 'deviceId',
  9. bundleName: 'com.neu.setResultOnAbilityResultTest1',
  10. abilityName: 'com.example.test.MainAbility',
  11. action: 'action1',
  12. entities: ['entity1'],
  13. type: 'MIMETYPE',
  14. uri: 'key={true,true,false}',
  15. parameters:
  16. {
  17. mykey0: 2222,
  18. mykey1: [1, 2, 3],
  19. mykey2: '[1, 2, 3]',
  20. mykey3: 'ssssssssssssssssssssssssss',
  21. mykey4: [false, true, false],
  22. mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
  23. mykey6: true,
  24. }
  25. }
  26. ],
  27. operationType: WantAgent.OperationType.START_ABILITIES,
  28. requestCode: 0,
  29. wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  30. };
  31. try {
  32. WantAgent.getWantAgent(wantAgentInfo).then((data) => {
  33. console.info('==========================>getWantAgentCallback=======================>');
  34. wantAgent = data;
  35. });
  36. WantAgent.getOperationType(wantAgent).then((OperationType) => {
  37. console.log('getOperationType success, OperationType: ' + OperationType);
  38. }).catch((err) => {
  39. console.log('getOperationType fail, err: ' + err);
  40. })
  41. } catch (paramError) {
  42. console.log('error: ' + paramError.code + ', ' + paramError.message);
  43. }

WantAgentFlags

系統(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屬性取代

OperationType

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

名稱

說明

UNKNOWN_TYPE

0

不識(shí)別的類型。

START_ABILITY

1

開啟一個(gè)有頁面的Ability。

START_ABILITIES

2

開啟多個(gè)有頁面的Ability。

START_SERVICE

3

開啟一個(gè)無頁面的ability。

SEND_COMMON_EVENT

4

發(fā)送一個(gè)公共事件。

CompleteData

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

名稱

類型

必填

說明

info

WantAgent

觸發(fā)的wantAgent。

want

Want

存在的被觸發(fā)的want。

finalCode

number

觸發(fā)wantAgent的請(qǐng)求代碼。

finalData

string

公共事件收集的最終數(shù)據(jù)。

extraInfo

{[key: string]: any}

額外數(shù)據(jù)。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)