1e41f4b71Sopenharmony_ci# @ohos.app.businessAbilityRouter (业务路由模块)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci本模块用于查询当前设备上安装的各种应用程序的路由ability信息。通过业务路由提供标准的业务模板和业务管理能力,开发者可以按照指定的业务类别注册标准业务,丰富的业务形成一个庞大的超市。系统应用或者三方应用可以从业务路由中获取所需业务,并选择合适的业务使用。同时业务路由提供统一的跳转管控规则,控制应用与业务之间的合理跳转,杜绝前后台任意的跳转行为,避免三方应用通过跳转变相分发,解决安全弱、体验差的问题。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 10 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci>本模块接口为系统接口。 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## 导入模块 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci``` ts 14e41f4b71Sopenharmony_ciimport businessAbilityRouter from '@ohos.app.businessAbilityRouter'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## 权限列表 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci| 权限 | 权限等级 | 描述 | 20e41f4b71Sopenharmony_ci| ------------------------------------------ | ------------ | -------------------- | 21e41f4b71Sopenharmony_ci| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | 可查询所有应用信息。 | 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci权限等级参考[权限APL等级说明](../../security/AccessToken/app-permission-mgmt-overview.md#权限机制中的基本概念)。 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci## BusinessType 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci此枚举值用于标识过滤条件类型。 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**系统能力:** 以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**系统API:** 此接口为系统接口。 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 34e41f4b71Sopenharmony_ci| ----------- | ---- | ------------------------------------ | 35e41f4b71Sopenharmony_ci| SHARE | 0 | 标识具有共享类型的ability信息。 | 36e41f4b71Sopenharmony_ci| UNSPECIFIED | 255 | 标识未指定类型的ability信息。 | 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci## BusinessAbilityFilter 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci此过滤值用于过滤查询的ability类型。 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci**系统API:** 此接口为系统接口。 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 必填 | 说明 | 47e41f4b71Sopenharmony_ci| ------------ | ------------ | ---- | ---- | -------------------------------------- | 48e41f4b71Sopenharmony_ci| businessType | [BusinessType](#businesstype) | 否 | 是 | 标识ability信息的类型。 | 49e41f4b71Sopenharmony_ci| mimeType | string | 否 | 否 | 标识支持mime类型的ability信息。 | 50e41f4b71Sopenharmony_ci| uri | string | 否 | 否 | 标识ability信息支持的uri。 | 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci## businessAbilityRouter.queryBusinessAbilityInfo 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ciqueryBusinessAbilityInfo(filter: BusinessAbilityFilter, callback: AsyncCallback\<Array\<BusinessAbilityInfo\>\>): void; 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci以异步方法通过给定的过滤条件查询ability信息。使用callback异步回调。成功返回查询到的路由ability信息,失败返回对应错误信息。 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci**系统API:** 此接口为系统接口。 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci**参数:** 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 67e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- | 68e41f4b71Sopenharmony_ci| filter | [BusinessAbilityFilter](#businessabilityfilter) | 是 | 支持按业务类型过滤的对象。 | 69e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[BusinessAbilityInfo](js-apis-bundleManager-businessAbilityInfo-sys.md#businessabilityinfo)\>\> | 是 | 回调函数。返回查询到的ability信息,否则为错误对象。 | 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**错误码**: 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 76e41f4b71Sopenharmony_ci| ------- | -------- | 77e41f4b71Sopenharmony_ci| 201 | Permission denied. | 78e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 79e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 3. Parameter verification failed. | 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**示例:** 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci```ts 84e41f4b71Sopenharmony_ciimport businessAbilityRouter from '@ohos.app.businessAbilityRouter'; 85e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_cilet filter: businessAbilityRouter.BusinessAbilityFilter = {businessType: businessAbilityRouter.BusinessType.SHARE}; 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_citry { 90e41f4b71Sopenharmony_ci businessAbilityRouter.queryBusinessAbilityInfo(filter, (error, data) => { 91e41f4b71Sopenharmony_ci if (error) { 92e41f4b71Sopenharmony_ci console.error('queryBusinessAbilityInfo failed ' + error.message); 93e41f4b71Sopenharmony_ci return; 94e41f4b71Sopenharmony_ci } 95e41f4b71Sopenharmony_ci console.info('queryBusinessAbilityInfo success'); 96e41f4b71Sopenharmony_ci }); 97e41f4b71Sopenharmony_ci} catch (error) { 98e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 99e41f4b71Sopenharmony_ci console.error('queryBusinessAbilityInfo failed ' + message); 100e41f4b71Sopenharmony_ci} 101e41f4b71Sopenharmony_ci``` 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci## businessAbilityRouter.queryBusinessAbilityInfo 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ciqueryBusinessAbilityInfo(filter: BusinessAbilityFilter): Promise\<Array\<BusinessAbilityInfo\>\>; 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci以异步方法通过给定的过滤条件查询ability信息。使用Promise异步回调,成功返回查询到的路由ability信息,失败返回对应错误信息。 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci**系统API:** 此接口为系统接口。 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci**参数:** 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 118e41f4b71Sopenharmony_ci| ----------- | ------------------------------- | ---- | --------------------------------------- | 119e41f4b71Sopenharmony_ci| filter | [BusinessAbilityFilter](#businessabilityfilter) | 是 | 包含要查询的ability信息的筛选类型。 | 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci**返回值:** 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci| 类型 | 说明 | 124e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------- | 125e41f4b71Sopenharmony_ci| Promise\<Array\<[BusinessAbilityInfo](js-apis-bundleManager-businessAbilityInfo-sys.md#businessabilityinfo)\>\> | Promise对象,返回符合过滤条件的ability信息。 | 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**错误码**: 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 132e41f4b71Sopenharmony_ci| ------- | -------- | 133e41f4b71Sopenharmony_ci| 201 | Permission denied. | 134e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 135e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 3. Parameter verification failed. | 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**示例:** 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci```ts 140e41f4b71Sopenharmony_ciimport businessAbilityRouter from '@ohos.app.businessAbilityRouter'; 141e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_cilet filter: businessAbilityRouter.BusinessAbilityFilter = {businessType: businessAbilityRouter.BusinessType.SHARE}; 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_citry { 146e41f4b71Sopenharmony_ci businessAbilityRouter.queryBusinessAbilityInfo(filter) 147e41f4b71Sopenharmony_ci .then(() => { 148e41f4b71Sopenharmony_ci console.info('queryBusinessAbilityInfo success'); 149e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 150e41f4b71Sopenharmony_ci console.error('queryBusinessAbilityInfo failed ' + error.message); 151e41f4b71Sopenharmony_ci }); 152e41f4b71Sopenharmony_ci} catch (error) { 153e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 154e41f4b71Sopenharmony_ci console.error('queryBusinessAbilityInfo failed ' + message); 155e41f4b71Sopenharmony_ci} 156e41f4b71Sopenharmony_ci``` 157