1e41f4b71Sopenharmony_ci# @ohos.app.businessAbilityRouter (Business Ability Router) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **businessAbilityRouter** module provides APIs for you to query the business ability information of applications installed on the device. It provides a unified template for you to register standard services by type. Based on the information, a system application or third-party application can obtain services that meet certain criteria and select a proper service. The module also provides unified rules to manage redirection between applications and services. It prevents arbitrary switching between the foreground and background and avoids the distribution of third-party applications by means of redirection.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci>The APIs provided by this module are system APIs.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Modules to Import
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci``` ts
14e41f4b71Sopenharmony_ciimport businessAbilityRouter from '@ohos.app.businessAbilityRouter';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## Required Permissions
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci| Permission                                      | APL    | Description                |
20e41f4b71Sopenharmony_ci| ------------------------------------------ | ------------ | -------------------- |
21e41f4b71Sopenharmony_ci| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all bundles. |
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ciFor details about the APL, see [Basic Concepts in the Permission Mechanism](../../security/AccessToken/app-permission-mgmt-overview.md#basic-concepts-in-the-permission-mechanism).
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci## BusinessType
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciEnumerates the types of business abilities.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**System API**: This is a system API.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| Name       | Value  | Description                                |
34e41f4b71Sopenharmony_ci| ----------- | ---- | ------------------------------------ |
35e41f4b71Sopenharmony_ci| SHARE       | 0    | Business ability of the share type. |
36e41f4b71Sopenharmony_ci| UNSPECIFIED | 255  | Business ability of an unspecified type.  |
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci## BusinessAbilityFilter
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ciDescribes the criteria for filtering business abilities.
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**System API**: This is a system API.
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci| Name        | Type        | Read-only | Mandatory | Description                                  |
47e41f4b71Sopenharmony_ci| ------------ | ------------ | ---- | ---- | -------------------------------------- |
48e41f4b71Sopenharmony_ci| businessType | [BusinessType](#businesstype) | No  | Yes  | Type of the business ability.          |
49e41f4b71Sopenharmony_ci| mimeType     | string       | No  | No  | MIME type supported by the business ability. |
50e41f4b71Sopenharmony_ci| uri          | string       | No  | No  | URI supported by the business ability.       |
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci## businessAbilityRouter.queryBusinessAbilityInfo
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ciqueryBusinessAbilityInfo(filter: BusinessAbilityFilter, callback: AsyncCallback\<Array\<BusinessAbilityInfo\>\>): void;
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ciObtains the business ability information based on the specified filter criteria. This API uses an asynchronous callback to return the result. If the operation is successful, the business ability information is returned; otherwise, an error object is returned.
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci**System API**: This is a system API.
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci**Parameters**
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci| Name      | Type    | Mandatory  | Description                                   |
67e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
68e41f4b71Sopenharmony_ci| filter | [BusinessAbilityFilter](#businessabilityfilter) | Yes   | Object used to filter the business abilities. |
69e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[BusinessAbilityInfo](js-apis-bundleManager-businessAbilityInfo-sys.md#businessabilityinfo)\>\> | Yes | Callback used to return the result. If the operation is successful, the business ability information that meets the filter criteria is returned; otherwise, an error object is returned. |
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**Error codes**
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci| ID | Error Message |
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**Example**
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_ciObtains the business ability information based on the specified filter criteria. This API uses a promise to return the result. If the operation is successful, the business ability information is returned; otherwise, an error object is returned.
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci**System API**: This is a system API.
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci**Parameters**
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci| Name      | Type                             | Mandatory  | Description                                   |
118e41f4b71Sopenharmony_ci| ----------- | ------------------------------- | ---- | --------------------------------------- |
119e41f4b71Sopenharmony_ci| filter | [BusinessAbilityFilter](#businessabilityfilter) | Yes   | Object used to filter the business abilities. |
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**Return value**
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci| Type                                                        | Description                                       |
124e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------- |
125e41f4b71Sopenharmony_ci| Promise\<Array\<[BusinessAbilityInfo](js-apis-bundleManager-businessAbilityInfo-sys.md#businessabilityinfo)\>\> | Promise used to return the business ability information that meets the filter criteria. |
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**Error codes**
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci| ID | Error Message |
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**Example**
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