codecamp

触发、取消、比较WantAgent实例和获取bundle名称的能力

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

说明

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

导入模块

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

WantAgent.getWantAgent

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

创建WantAgent(callback形式)。 创建失败返回的WantAgent为空值。

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

参数:

参数名

类型

必填

说明

info

WantAgentInfo

WantAgent信息。

callback

AsyncCallback<WantAgent>

创建WantAgent的回调方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //getWantAgent回调
  3. function getWantAgentCallback(err, data) {
  4. console.info('==========================>getWantAgentCallback=======================>');
  5. }
  6. //WantAgentInfo对象
  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>

创建WantAgent(Promise形式)。 创建失败返回的WantAgent为空值。

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

参数:

参数名

类型

必填

说明

info

WantAgentInfo

WantAgent信息。

返回值:

类型

说明

Promise<WantAgent>

以Promise形式返回WantAgent。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //WantAgentInfo对象
  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实例的包名(callback形式)。

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

callback

AsyncCallback<string>

获取WantAgent实例的包名的回调方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent;
  4. //getWantAgent回调
  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对象
  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回调
  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实例的包名(Promise形式)。

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

返回值:

类型

说明

Promise<string>

以Promise形式返回获取WantAgent实例的包名。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent;
  4. //WantAgentInfo对象
  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实例的用户ID(callback形式)。

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

callback

AsyncCallback<number>

获取WantAgent实例的用户ID的回调方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent;
  4. //getWantAgent回调
  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对象
  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回调
  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实例的用户ID(Promise形式)。

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

返回值:

类型

说明

Promise<number>

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

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent;
  4. //WantAgentInfo对象
  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实例(callback形式)。

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

callback

AsyncCallback<void>

取消WantAgent实例的回调方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent;
  4. //getWantAgent回调
  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对象
  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回调
  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实例(Promise形式)。

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

返回值:

类型

说明

Promise<void>

以Promise形式获取异步返回结果。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent;
  4. //WantAgentInfo对象
  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

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

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

triggerInfo

TriggerInfo

TriggerInfo对象。

callback

AsyncCallback<CompleteData>

主动激发WantAgent实例的回调方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent;
  4. //getWantAgent回调
  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对象
  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回调
  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

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

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

otherAgent

WantAgent

WantAgent对象。

callback

AsyncCallback<boolean>

判断两个WantAgent实例是否相等的回调方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent1;
  4. let wantAgent2;
  5. //getWantAgent回调
  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对象
  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回调
  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>

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

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

otherAgent

WantAgent

WantAgent对象。

返回值:

类型

说明

Promise<boolean>

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

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent1;
  4. let wantAgent2;
  5. //WantAgentInfo对象
  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;

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

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

callback

AsyncCallback<number>

获取一个WantAgent的OperationType信息的回调方法。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent;
  4. //WantAgentInfo对象
  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>;

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

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

参数:

参数名

类型

必填

说明

agent

WantAgent

WantAgent对象。

返回值:

类型

说明

Promise<number>

以Promise形式返回获取operationType的结果。

示例:

  1. import WantAgent from '@ohos.app.ability.wantAgent';
  2. //wantAgent对象
  3. let wantAgent;
  4. //WantAgentInfo对象
  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

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

名称

说明

ONE_TIME_FLAG

0

WantAgent仅能使用一次。

NO_BUILD_FLAG

1

如果描述WantAgent对象不存在,则不创建它,直接返回null。

CANCEL_PRESENT_FLAG

2

在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象。

UPDATE_PRESENT_FLAG

3

使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据。

CONSTANT_FLAG

4

WantAgent是不可变的。

REPLACE_ELEMENT

5

当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代

REPLACE_ACTION

6

当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代

REPLACE_URI

7

当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代

REPLACE_ENTITIES

8

当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代

REPLACE_BUNDLE

9

当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代

OperationType

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

名称

说明

UNKNOWN_TYPE

0

不识别的类型。

START_ABILITY

1

开启一个有页面的Ability。

START_ABILITIES

2

开启多个有页面的Ability。

START_SERVICE

3

开启一个无页面的ability。

SEND_COMMON_EVENT

4

发送一个公共事件。

CompleteData

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

名称

类型

必填

说明

info

WantAgent

触发的wantAgent。

want

Want

存在的被触发的want。

finalCode

number

触发wantAgent的请求代码。

finalData

string

公共事件收集的最终数据。

extraInfo

{[key: string]: any}

额外数据。

应用组件间的信息传递
want中操作want常数和解释Flags说明的能力
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

媒体组件

像素

枚举

类型

接口

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }