鸿蒙5.0开发进阶:@ohos.app.ability.wantAgent (WantAgent模块)

HarmonyOS WantAgent 迁移指南:从@ohos.wantAgent到@ohos.app.ability.wantAgent的5个关键变更点 本文详细解析了HarmonyOS WantAgent从`@ohos.wantAgent`迁移到`@ohos.app.ability.wantAgent`的5个关键变更点,包括模块路径调整、多线程支持、错误码体系重构等。通过实战示例和迁移检查清单,帮助开发者高效完成API升级,提升应用性能和兼容性。 阅读详情

往期鸿蒙全套实战文章必看:(文中附带全栈鸿蒙学习资料)


@ohos.app.ability.wantAgent (WantAgent模块)

app.ability.WantAgent是一个封装了Want对象的类,允许应用程序能够在未来的某个时间点执行该Want。该模块提供了创建WantAgent实例、获取实例的用户ID、获取want信息、比较WantAgent实例和获取包名等功能。

WantAgent的一个典型应用场景是通知处理。例如,当用户点击通知时,会触发WantAgent的trigger接口,并拉起目标应用。该模块将会取代@ohos.wantAgent模块,建议优先使用本模块。

说明

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

导入模块

import { wantAgent } from '@kit.AbilityKit';

wantAgent.getWantAgent

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

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

三方应用只能设置自己应用的Ability。

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
infoWantAgentInfo是WantAgent信息。
callbackAsyncCallback<WantAgent>是创建WantAgent的回调方法。

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000007Service busy, there are concurrent tasks, waiting for retry.
16000151Invalid wantagent object.

示例:

import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgentData: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
  wants: [
    {
      deviceId: 'deviceId',
      bundleName: 'com.example.myapplication',
      abilityName: 'EntryAbility',
      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,
      }
    } as Want
  ],
  actionType: wantAgent.OperationType.START_ABILITY,
  requestCode: 0,
  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
  if (err) {
    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
  } else {
    wantAgentData = data;
  }
}

try {
  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
  console.error(`getWantAgent failed, error: ${JSON.stringify(err)}`);
}

wantAgent.getWantAgent

getWantAgent(info: WantAgentInfo): Promise<WantAgent>

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

三方应用只能设置自己应用的Ability。

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
infoWantAgentInfo是WantAgent信息。

返回值:

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

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000007Service busy, there are concurrent tasks, waiting for retry.
16000151Invalid wantagent object.

示例:

import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let wantAgentData: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
  wants: [
    {
      deviceId: 'deviceId',
      bundleName: 'com.example.myapplication',
      abilityName: 'EntryAbility',
      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,
      }
    } as Want
  ],
  actionType: wantAgent.OperationType.START_ABILITY,
  requestCode: 0,
  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

try {
  wantAgent.getWantAgent(wantAgentInfo).then((data) => {
    wantAgentData = data;
  }).catch((err: BusinessError) => {
    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
  });
} catch (err) {
  console.error(`getWantAgent failed! ${err.code} ${err.message}`);
}

wantAgent.getBundleName

getBundleName(agent: WantAgent, callback: AsyncCallback<string>): void

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。
callbackAsyncCallback<string>是获取WantAgent实例的包名的回调方法。

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000007Service busy, there are concurrent tasks, waiting for retry.
16000151Invalid wantagent object.

示例:

import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgentData: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
  wants: [
    {
      deviceId: 'deviceId',
      bundleName: 'com.example.myapplication',
      abilityName: 'EntryAbility',
      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,
      }
    } as Want
  ],
  actionType: wantAgent.OperationType.START_ABILITY,
  requestCode: 0,
  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
  if (err) {
    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
  } else {
    wantAgentData = data;
  }
  //getBundleName回调
  let getBundleNameCallback = (err: BusinessError, data: string) => {
    if (err) {
      console.error(`getBundleName failed! ${err.code} ${err.message}`);
    } else {
      console.info(`getBundleName ok! ${JSON.stringify(data)}`);
    }
  }
  try {
    wantAgent.getBundleName(wantAgentData, getBundleNameCallback);
  } catch (err) {
    console.error(`getBundleName failed! ${err.code} ${err.message}`);
  }
}

try {
  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
  console.error(`getWantAgent failed! ${err.code} ${err.message}`);
}

wantAgent.getBundleName

getBundleName(agent: WantAgent): Promise<string>

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。

返回值:

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

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000007Service busy, there are concurrent tasks, waiting for retry.
16000151Invalid wantagent object.

示例:

import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgentData: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
  wants: [
    {
      deviceId: 'deviceId',
      bundleName: 'com.example.myapplication',
      abilityName: 'EntryAbility',
      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,
      }
    } as Want
  ],
  actionType: wantAgent.OperationType.START_ABILITY,
  requestCode: 0,
  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
  if (err) {
    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
  } else {
    wantAgentData = data;
  }
  try {
    wantAgent.getBundleName(wantAgentData).then((data)=>{
      console.info(`getBundleName ok! ${JSON.stringify(data)}`);
    }).catch((err: BusinessError)=>{
      console.error(`getBundleName failed! ${err.code} ${err.message}`);
    });
  } catch(err){
    console.error(`getBundleName failed! ${err.code} ${err.message}`);
  }
}
try {
  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err) {
  console.error(`getWantAgent failed! ${err.code} ${err.message}`);
}

wantAgent.getUid

getUid(agent: WantAgent, callback: AsyncCallback<number>): void

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。
callbackAsyncCallback<number>是获取WantAgent实例的用户ID的回调方法。

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000007Service busy, there are concurrent tasks, waiting for retry.
16000151Invalid wantagent object.

示例:


import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgentData: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
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,
}
} as Want
],
actionType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
if (err) {
console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
} else {
wantAgentData = data;
}
//getUid回调
let getUidCallback = (err: BusinessError, data: number) => {
if (err) {
console.error(`getUid failed! ${err.code} ${err.message}`);
} else {
console.info(`getUid ok! ${JSON.stringify(data)}`);
}
}
try {
wantAgent.getUid(wantAgentData, getUidCallback);
} catch (err) {
console.error(`getUid failed! ${err.code} ${err.message}`);
}
}

try {
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
console.error(`getWantAgent failed! ${err.code} ${err.message}`);
}

wantAgent.getUid

getUid(agent: WantAgent): Promise<number>

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。

返回值:

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

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000007Service busy, there are concurrent tasks, waiting for retry.
16000151Invalid wantagent object.

示例:

import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgentData: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
  wants: [
    {
      deviceId: 'deviceId',
      bundleName: 'com.example.myapplication',
      abilityName: 'EntryAbility',
      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,
      }
    } as Want
  ],
  actionType: wantAgent.OperationType.START_ABILITY,
  requestCode: 0,
  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
  if (err) {
    console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
  } else {
    wantAgentData = data;
  }
  try {
    wantAgent.getUid(wantAgentData).then((data) => {
      console.info(`getUid ok! ${JSON.stringify(data)}`);
    }).catch((err: BusinessError) => {
      console.error(`getUid failed! ${err.code} ${err.message}`);
    });
  } catch (err) {
    console.error(`getUid failed! ${err.code} ${err.message}`);
  }
}

try {
  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
  console.error(`getWantAgent failed! ${err.code} ${err.message}`);
}

wantAgent.cancel

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

取消WantAgent实例(callback形式)。

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。
callbackAsyncCallback<void>是取消WantAgent实例的回调方法。

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000007Service busy, there are concurrent tasks, waiting for retry.
16000151Invalid wantagent object.

示例:

import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgentData: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
  wants: [
    {
      deviceId: 'deviceId',
      bundleName: 'com.example.myapplication',
      abilityName: 'EntryAbility',
      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,
      }
    } as Want
  ],
  actionType: wantAgent.OperationType.START_ABILITY,
  requestCode: 0,
  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
  if (err) {
    console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
  } else {
    wantAgentData = data;
  }
  //cancel回调
  let cancelCallback = (err: BusinessError, data: void) => {
    if (err) {
      console.error(`cancel failed! ${err.code} ${err.message}`);
    } else {
      console.info(`cancel ok!`);
    }
  }
  try {
    wantAgent.cancel(wantAgentData, cancelCallback);
  } catch (err) {
    console.error(`cancel failed! ${err.code} ${err.message}`);
  }
}

try {
  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
  console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}

wantAgent.cancel

cancel(agent: WantAgent): Promise<void>

取消WantAgent实例(Promise形式)。

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。

返回值:

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

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000007Service busy, there are concurrent tasks, waiting for retry.
16000151Invalid wantagent object.

示例:


import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgentData: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
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,
}
} as Want
],
actionType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
if (err) {
console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
} else {
wantAgentData = data;
}
try {
wantAgent.cancel(wantAgentData).then((data) => {
console.info('cancel ok!');
}).catch((err: BusinessError) => {
console.error(`cancel failed! ${err.code} ${err.message}`);
});
} catch (err) {
console.error(`cancel failed! ${err.code} ${err.message}`);
}
}

try {
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}

wantAgent.trigger

trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback<CompleteData>): void

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。
triggerInfoTriggerInfo是TriggerInfo对象。
callbackAsyncCallback<CompleteData>否主动激发WantAgent实例的回调方法。

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

示例:

import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgentData: WantAgent;
// triggerInfo
let triggerInfo: wantAgent.TriggerInfo = {
  code: 0 //自定义义结果码
};
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
  wants: [
    {
      deviceId: 'deviceId',
      bundleName: 'com.example.myapplication',
      abilityName: 'EntryAbility',
      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,
      }
    } as Want
  ],
  actionType: wantAgent.OperationType.START_ABILITY,
  requestCode: 0,
  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
  if (err) {
    console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
  } else {
    wantAgentData = data;
  }
  //trigger回调
  let triggerCallback = (err: BusinessError, data: wantAgent.CompleteData) => {
    if (err) {
      console.error(`getUid failed! ${err.code} ${err.message}`);
    } else {
      console.info(`getUid ok! ${JSON.stringify(data)}`);
    }
  }
  try {
    wantAgent.trigger(wantAgentData, triggerInfo, triggerCallback);
  } catch (err) {
    console.error(`getUid failed! ${err.code} ${err.message}`);
  }
}

try {
  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
  console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}

wantAgent.equal

equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>): void

判断两个WantAgent实例是否相等(Callback形式),以此来判断是否是来自同一应用的相同操作。

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。
otherAgentWantAgent是WantAgent对象。
callbackAsyncCallback<boolean>是判断两个WantAgent实例是否相等的回调方法。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等。

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

示例:


import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgent1: WantAgent;
let wantAgent2: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
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,
}
} as Want
],
actionType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
if (err) {
console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
} else {
wantAgent1 = data;
wantAgent2 = data;
}
//equal回调
let equalCallback = (err: BusinessError, data: boolean) => {
if (err) {
console.error(`equal failed! ${err.code} ${err.message}`);
} else {
console.info(`equal ok! ${JSON.stringify(data)}`);
}
}
try {
wantAgent.equal(wantAgent1, wantAgent2, equalCallback);
} catch (err) {
console.error(`equal failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}
}

try {
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}

wantAgent.equal

equal(agent: WantAgent, otherAgent: WantAgent): Promise<boolean>

判断两个WantAgent实例是否相等(Promise形式),以此来判断是否是来自同一应用的相同操作。

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。
otherAgentWantAgent是WantAgent对象。

返回值:

类型说明
Promise<boolean>以Promise形式返回获取判断两个WantAgent实例是否相等的结果。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等。

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

示例:


import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgent1: WantAgent;
let wantAgent2: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
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,
}
} as Want
],
actionType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
if (err) {
console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
} else {
wantAgent1 = data;
wantAgent2 = data;
}
try {
wantAgent.equal(wantAgent1, wantAgent2).then((data) => {
console.info(`equal ok! ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`equal failed! ${err.code} ${err.message}`);
})
} catch (err) {
console.error(`equal failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}
}

try {
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}

wantAgent.getOperationType

getOperationType(agent: WantAgent, callback: AsyncCallback<number>): void

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。
callbackAsyncCallback<number>是获取一个WantAgent的OperationType信息的回调方法。

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000007Service busy, there are concurrent tasks, waiting for retry.
16000015Service timeout.
16000151Invalid wantagent object.

示例:


import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgentData: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
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,
}
} as Want
],
actionType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
if (err) {
console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
} else {
wantAgentData = data;
}
//getOperationTypeCallback回调
let getOperationTypeCallback = (err: BusinessError, data: number) => {
if (err) {
console.error(`getOperationType failed! ${err.code} ${err.message}`);
} else {
console.info(`getOperationType ok! ${JSON.stringify(data)}`);
}
}
try {
wantAgent.getOperationType(wantAgentData, getOperationTypeCallback);
} catch (err) {
console.error(`getOperationTypeCallback failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}
}

try {
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}

wantAgent.getOperationType

getOperationType(agent: WantAgent): Promise<number>

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
agentWantAgent是WantAgent对象。

返回值:

类型说明
Promise<number>以Promise形式返回获取operationType的结果。

错误码:

以下错误码详细介绍。

错误码ID错误信息
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000007Service busy, there are concurrent tasks, waiting for retry.
16000015Service timeout.
16000151Invalid wantagent object.

错误码详细介绍

示例:


import { wantAgent, Want } from '@kit.AbilityKit';
import type { WantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

//wantAgent对象
let wantAgentData: WantAgent;
//WantAgentInfo对象
let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
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,
}
} as Want
],
actionType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};

//getWantAgent回调
function getWantAgentCallback(err: BusinessError, data: WantAgent) {
if (err) {
console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
} else {
wantAgentData = data;
}
try {
wantAgent.getOperationType(wantAgentData).then((data) => {
console.info(`getOperationType ok! ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getOperationType failed! ${err.code} ${err.message}`);
});
} catch (err) {
console.error(`getOperationType failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}
}

try {
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch (err) {
console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
}

WantAgentFlags

表示使用WantAgent类型的枚举。

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

名称值说明
ONE_TIME_FLAG0WantAgent仅能使用一次。
NO_BUILD_FLAG1如果描述WantAgent对象不存在,则不创建它,直接返回null。
CANCEL_PRESENT_FLAG2在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象。
UPDATE_PRESENT_FLAG3使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据。
CONSTANT_FLAG4WantAgent是不可变的。
REPLACE_ELEMENT5当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代。当前版本暂不支持。
REPLACE_ACTION6当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代。当前版本暂不支持。
REPLACE_URI7当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代。当前版本暂不支持。
REPLACE_ENTITIES8当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代。当前版本暂不支持。
REPLACE_BUNDLE9当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代。当前版本暂不支持。

OperationType

表示操作WantAgent类型的枚举。

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

名称值说明
UNKNOWN_TYPE0不识别的类型。
START_ABILITY1开启一个有页面的Ability。
START_ABILITIES2开启多个有页面的Ability。
START_SERVICE3开启一个无页面的Ability(仅在FA模型下生效)。
SEND_COMMON_EVENT4发送一个公共事件。

CompleteData

表示主动激发WantAgent返回的数据。

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

名称类型只读可选说明
infoWantAgent否否触发的wantAgent。
wantWant否否存在的被触发的want。
finalCodenumber否否触发wantAgent的请求代码。
finalDatastring否否公共事件收集的最终数据。
extraInfoRecord<string, Object>否是额外数据。

HarmonyOS实战开发:@ohos.app.ability.wantAgent (构建与触发WantAgent) 本文详细介绍了HarmonyOS中@ohos.app.ability.wantAgent模块的使用方法,包括WantAgent的构建与触发。通过WantAgent,开发者可以打包操作意图并在适当时机执行,适用于通知栏点击、定时任务等场景。文章还提供了API 9及以上版本的配置示例和最佳实践,帮助开发者高效实现功能。 阅读详情

相关推荐

HarmonyOS API 9 WantAgent 模块实战:3种跨应用启动场景与 5 个关键 Flag 解析

本文深入解析HarmonyOS API 9中的WantAgent模块,详细介绍了3种跨应用启动场景(启动特定页面、发送公共事件、服务调用)和5个关键Flag(UPDATE_PRESENT_FLAG、ONE_TIME_FLAG等)的使用方法。通过实战代码示例,帮助开发者掌握WantAgent在HarmonyOS应用开发中的高级应用技巧,提升跨应用交互能力。

weixin_32821533的博客 252

HarmonyOS实战开发:@ohos.app.ability.wantAgent (WantAgent模块)

该模块将会取代@ohos.wantAgent模块,建议优先使用本模块。

2401_84194030的博客 1450

HarmonyOS 6原生重构:从App开发到系统能力编排的范式迁移

HarmonyOS 6并非Android兼容层升级,而是以Stage模型、ArkTS语言和分布式能力为核心的全新操作系统范式。其核心原理在于将应用生命周期、后台调度、安全执行等关键逻辑收归系统管控,强制开发者转向‘能力调用’而非‘代码堆砌’——例如ExtensionAbility替代Service、TEE可信执行环境开箱即用、WantAgent实现跨设备意图调度。这一转变带来显著技术价值:更细粒度的资源控制、更高确定性的安全边界、更轻量的业务逻辑。典型应用场景涵盖政务核验(交管12123)、出行协同(高德融

weixin_34413103的博客 518

【鸿蒙HarmonyOS开发笔记】通知模块之为通知添加行为意图

接口说明具体接口描述,详见WantAgent接口文档。创建WantAgent触发WantAgent意图取消WantAgent获取WantAgent的want判断两个WantAgent实例是否相等。

温的打怪之旅 1417

鸿蒙音乐播放器源码拆解:ArkTS与媒体框架实战

声明式UI框架正在改变移动应用的开发方式,ArkTS作为鸿蒙生态的核心语言,配合ArkUI的响应式状态管理,让复杂界面交互变得更易维护。在音频领域,HarmonyOS媒体框架提供了AVPlayer等组件支撑本地播放能力,但实现一个完整的音乐应用还需处理权限请求、媒体库扫描、通知栏控制及后台长时任务等关键环节。这些技术不仅用于播放器,也是鸿蒙应用开发的通用基础。通过分析一个完整开源的音乐播放器工程,可以快速理解生命周期管理、状态机设计和分布式部署的实际用法,帮助开发者从其他平台平滑迁移。这套拆解覆盖从架构到实

weixin_34025151的博客 443

深入解析NPN与PNP传感器驱动电路的设计逻辑与实战应用

本文深入解析NPN与PNP传感器驱动电路的设计逻辑与实战应用,详细对比两者的电流路径差异和电平变化特性。通过实际案例分享电路设计要点,包括上拉电阻选择、保护二极管配置等,并提供工业应用中的选型策略和常见故障排查指南,帮助工程师优化传感器系统集成。

weixin_42561476的博客 472

鸿蒙API14开发【@ohos.app.ability.wantAgent (WantAgent模块)(系统接口)】应用框架api

app.ability.WantAgent模块提供了创建WantAgent实例、获取实例的用户ID、获取want信息、比较WantAgent实例和获取bundle名称等能力。该模块将会取代[@ohos.wantAgent]模块,建议优先使用本模块。

bbq的博客 578

用ADS复现一篇MTT顶刊的GAN功率放大器:从理论推导到版图仿真的完整避坑指南

本文详细解析了如何利用ADS软件复现MTT顶刊中的E/F3类GaN功率放大器设计,从理论推导到版图仿真的全流程。通过核心设计理念解析、ADS环境配置、输出匹配网络优化等关键步骤,提供了一套完整的工程实践指南,帮助工程师跨越学术理论与实际应用的鸿沟,实现高效率射频功率放大器的设计。

weixin_30654583的博客 315

鸿蒙5.0&next开发【为通知添加行为意图】用户通知服务

当发布通知时,如果期望用户可以通过点击通知栏拉起目标应用组件或发布公共事件,可以通过Ability Kit申请[WantAgent]封装至通知消息中。

bbq的博客 690

三相SST固态变压器详细设计案例

本案例针对400kVA、30kHz三相固态变压器(SST)开展详细设计,核心采用输入串联输出并联(ISOP)拓扑架构(模块化多电平矩阵变换器M3C简化版),重点完成高频变压器的参数计算、绕组设计、损耗分析及液冷温升验证,同时覆盖系统级架构设计、半导体损耗估算及整机效率优化,全流程基于当前电力电子技术可行性展开。

qq_32103755的博客 3315

微信小程序报错:“errno“:600001,“errMsg“:“uploadFile:fail errcode:-105 cronet_error_code:-105 error_msg:net::

uploadFile:fail errcode:-105 cronet_error_code:-105 error_msg:net::ERR_NAME_NOT_RESOLVED,uniApp微信小程序使用uni.uploadFile出现报错,微信小程序如何解决wx.uploadFile报错,如何解决这个问题,微信小程序真机报错,微信小程序报错"errno":600001,"errMsg":"uploadFile:fail errcode:-105 cronet_error_code:-105 error_m

✅ 精选推荐文章 3831

【Harmony OS - 消息通知】

Harmony OS - 信息通知

weixin_44273311的博客 881

Kile5报错—> ARM-Compiler ‘Default Compiler Version 5‘ which is not available安装使用Compiler Version 5 的办法

Kile5报错—> ARM-Compiler ‘Default Compiler Version 5‘ which is not available安装使用Compiler Version 5 的办法

weixin_72050316的博客 1190

鸿蒙NEXT开发:FA模型能力的接口-@ohos.app.ability.wantAgent (WantAgent模块)

app.ability.WantAgent是一个封装了Want对象的类.....

ZPYQAQ的博客 975

Codex入门10-Goal自主任务(进阶必学:设定目标就不管了,AI自己干活到完成)

/goal 是Codex CLI最强大的进阶功能——设定一个目标,AI就会制定计划、分步执行、自我测试、持续迭代,即使你关掉终端也会继续。本文详解/goal的工作原理、配置启用方法、常用命令(pause/resume/status/clear),以及如何写出高质量的目标描述让AI高效自主完成任务。

yueyeguzhuo的专栏 456

大模型自我认知微调的实战教程

本文主要介绍了大模型自我认知微调的实战教程,希望对学习大语言模型的同学们有所帮助。微调成功并保留原有能力的截图如下所示: 文章目录 1. 前言 2. 配置环境 2.1 安装虚拟环境 2.2 安装依赖库 3. 实战代码 3.1 配置数据集 3.2 lora微调

herosunly的博客 4万+

鸿蒙API14开发【@ohos.app.ability.wantAgent (WantAgent模块)】应用框架api

app.ability.WantAgent是一个封装了[Want]对象的类,允许应用程序能够在未来的某个时间点执行该Want。该模块提供了创建WantAgent实例、获取实例的用户ID、获取want信息、比较WantAgent实例和获取包名等功能。 WantAgent的一个典型应用场景是通知处理。例如,当用户点击通知时,会触发WantAgent的[trigger]接口,并拉起目标应用。该模块将会取代[@ohos.wantAgent]模块,建议优先使用本模块。

bbq的博客 841

使用Simulink对基于GaN器件的高频电源进行建模与仿真,重点在于优化其效率

本文介绍了基于Simulink的GaN器件高频电源仿真建模方法。通过7个步骤详细讲解系统构建过程:从创建模型、设置电源、配置GaN开关网络,到添加磁性元件、负载和控制器设计,最后进行仿真分析。重点探讨了效率优化策略,包括开关频率选择、磁性元件优化、散热设计改进及控制策略调整。该教程为GaN器件在电力电子系统中的应用提供了完整的仿真流程指导,有助于设计人员验证方案并优化性能。

amy_mhd的博客 235

鸿蒙API13开发【@ohos.app.ability.wantAgent (WantAgent模块)】通用能力的接口

app.ability.WantAgent是一个封装了[Want]对象的类,允许应用程序能够在未来的某个时间点执行该Want。该模块提供了创建WantAgent实例、获取实例的用户ID、获取want信息、比较WantAgent实例和获取包名等功能。

鸿蒙的技术博客 1094

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

鸿蒙API13开发【@ohos.wantAgent (WantAgent模块)】接口依赖的元素及定义

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

鸿蒙的技术博客 728

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

从 React 到 ArkTS:手把手教你实现鸿蒙习惯打卡 App

XEngine是HarmonyOS的GPU加速引擎,通过多项特性提升图形应用的渲染性能:1)VRS可变速率着色技术可智能降低非焦点区域渲染精度;2)提供空间/神经网络/时序三种超分方案,实现低分辨率渲染+高质量放大;3)支持光线追踪反射和全局光照,增强画面真实感;4)HPS高性能着色器可加速粒子系统排序。这些功能需在Native层通过C API调用,使用前需检测设备兼容性。开发者可根据需求选择OpenGL ES或Vulkan接口,其中光线追踪和HPS仅支持Vulkan。XEngine特别适合游戏和图形密集型

weixin_42299977的博客 379

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

HarmonyOS API 9 WantAgent 模块实战:3种OperationType与10个Flag的完整应用场景解析

本文深入解析HarmonyOS API 9中WantAgent模块的3种OperationType与10个Flag的完整应用场景,通过实战案例演示如何实现精准的任务调度。涵盖单Ability启动、多Ability并行启动及事件广播等核心功能,帮助开发者高效利用WantAgent进行跨组件/应用通信,提升HarmonyOS应用开发效率。

weixin_33416697的博客 317

HarmonyOS 5.0跨设备开发实战与优化

分布式计算技术通过将任务分解到多个设备协同处理,实现了资源的高效利用与用户体验的无缝衔接。其核心原理在于分布式数据管理、软总线通信和设备虚拟化等技术栈的融合。在移动互联网时代,这种技术能显著降低开发复杂度,提升多端一致性,特别适合智能家居、移动办公等需要跨设备联动的场景。以HarmonyOS 5.0为例,其分布式能力支持一套代码适配手机、平板和PC多终端,通过ArkTS语言和响应式布局实现高效开发。开发者借助DevEco Studio工具链,可快速构建具备实时数据同步、设备自适应UI等特性的应用,实测显示其

weixin_33795806的博客 352

HarmonyOS 通知意图

就例如说 我们某个微信好友发消息给我们 我们 点击系统通知 可以直接跳到你们的聊天界面。然后 abilityName 要用 哪个 Ability 写入口文件的名字上去就好了。按我这样写 绑定给通知 请求对象的 wantAgent属性就好了。之前的文章 我们讲了 harmonyos 中的 基础和进度条通知。通知意图 简单说 就是 当我们点击某个通知 如下图。然后 我们点出通知 后 将应用切到后台 然后点击通知。这就是 最基本的 一个通知模板 之前我们也讲过了。然后 我们声明对象。

weixin_45966674的博客 618

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

WantAgent封装了一个行为意图信息,可以通过WantAgent.trigger接口主动触发,也可以通过与通知绑定被动触发。

weixin_69135651的博客 1317

鸿蒙5.0开发进阶:ArkTS API-WantAgentInfo

定义触发WantAgent所需要的信息,可以作为getWantAgent的入参创建指定的WantAgent对象。

Androidbye的博客 1105
上一篇: 鸿蒙5.0开发进阶:@ohos.app.ability.Want (Want)
下一篇: 鸿蒙5.0开发进阶:@ohos.app.ability.wantConstant (wantConstant)
懂你的大海
博客等级 码龄6年 9049粉丝 1381原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值