• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle.launcherBundleManager (launcherBundleManager)
2
3The **bundle.launcherBundleManager** module providers APIs for the **Home Screen** application to obtain the launcher ability information and shortcut information.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
13```
14
15
16## launcherBundlemanager.getLauncherAbilityInfo<sup>9+</sup>
17
18getLauncherAbilityInfo(bundleName: string, userId: number, callback: AsyncCallback<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>>) : void;
19
20Obtains the launcher ability information based on the given bundle name and user ID. This API uses an asynchronous callback to return the result.
21
22**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
23
24**System API**: This is a system API.
25
26**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
27
28**Parameters**
29
30| Name    | Type  | Mandatory| Description        |
31| ---------- | ------ | ---- | -------------- |
32| bundleName | string | Yes  | Bundle name of the application.|
33| userId     | number | Yes  | User ID.|
34
35**Return value**
36
37| Type                               | Description                                               |
38| ----------------------------------- | --------------------------------------------------- |
39| AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Callback used to return the **LauncherAbilityInfo** object obtained.|
40
41**Error codes**
42
43For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
44
45| ID| Error Message                                |
46| -------- | ---------------------------------------- |
47| 17700001 | The specified bundle name is not found.  |
48| 17700004 | The specified userId is not found.      |
49
50**Example**
51
52```ts
53import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
54
55try {
56    launcherBundleManager.getLauncherAbilityInfo('com.example.demo', 100, (errData, data) => {
57        if (errData !== null) {
58            console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
59        }
60        console.log("data is " + JSON.stringify(data));
61    })
62} catch (errData) {
63    console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
64}
65```
66
67## launcherBundlemanager.getLauncherAbilityInfo<sup>9+</sup>
68
69getLauncherAbilityInfo(bundleName: string, userId: number) : Promise<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>>;
70
71Obtains the launcher ability information based on the given bundle name and user ID. This API uses a promise to return the result.
72
73**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
74
75**System API**: This is a system API.
76
77**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
78
79**Parameters**
80
81| Name    | Type  | Mandatory| Description        |
82| ---------- | ------ | ---- | -------------- |
83| bundleName | string | Yes  | Bundle name of the application.|
84| userId     | number | Yes  | User ID.|
85
86**Return value**
87
88| Type                         | Description                                              |
89| ----------------------------- | -------------------------------------------------- |
90| Promise\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Promise used to return the **LauncherAbilityInfo** object obtained.|
91
92**Error codes**
93
94For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
95
96| ID| Error Message                                |
97| -------- | ---------------------------------------- |
98| 17700001 | The specified bundle name is not found.  |
99| 17700004 | The specified userId is not found.       |
100
101**Example**
102
103```typescript
104import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
105
106try {
107    launcherBundleManager.getLauncherAbilityInfo("com.example.demo", 100).then(data => {
108        console.log("data is " + JSON.stringify(data));
109    }).catch (errData => {
110        console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
111    })
112} catch (errData) {
113    console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
114}
115```
116
117## launcherBundlemanager.getAllLauncherAbilityInfo<sup>9+</sup>
118
119getAllLauncherAbilityInfo(userId: number, callback: AsyncCallback<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>>) : void;
120
121Obtains the launcher ability information of all applications based on the given user ID. This API uses an asynchronous callback to return the result.
122
123**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
124
125**System API**: This is a system API.
126
127**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
128
129**Parameters**
130
131| Name| Type  | Mandatory| Description        |
132| ------ | ------ | ---- | -------------- |
133| userId | number | Yes  | User ID.|
134
135**Return value**
136
137| Type                               | Description                                                   |
138| ----------------------------------- | ------------------------------------------------------- |
139| AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Callback used to return the array of **LauncherAbilityInfo** objects obtained.|
140
141**Error codes**
142
143For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
144
145| ID| Error Message                               |
146| -------- | ---------------------------------------- |
147| 17700004 | The specified userId is not found.      |
148
149Example
150
151```ts
152import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
153
154try {
155    launcherBundleManager.getAllLauncherAbilityInfo(100, (errData, data) => {
156        if (errData !== null) {
157            console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
158        }
159        console.log("data is " + JSON.stringify(data));
160    });
161} catch (errData) {
162    console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
163}
164```
165## launcherBundlemanager.getAllLauncherAbilityInfo<sup>9+</sup>
166
167getAllLauncherAbilityInfo(userId: number) : Promise<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>>;
168
169Obtains the launcher ability information of all applications based on the given user ID. This API uses a promise to return the result.
170
171**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
172
173**System API**: This is a system API.
174
175**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
176
177**Parameters**
178
179| Name| Type  | Mandatory| Description        |
180| ------ | ------ | ---- | -------------- |
181| userId | number | Yes  | User ID.|
182
183**Return value**
184
185| Type                         | Description                                                  |
186| ----------------------------- | ------------------------------------------------------ |
187| Promise\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Promise used to return the array of **LauncherAbilityInfo** objects obtained.|
188
189**Error codes**
190
191For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
192
193| ID| Error Message                               |
194| -------- | ---------------------------------------- |
195| 17700004 | The specified userId is not found.      |
196
197**Example**
198
199```ts
200import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
201
202try {
203    launcherBundleManager.getAllLauncherAbilityInfo(100).then(data => {
204        console.log("data is " + JSON.stringify(data));
205    }).catch (errData => {
206        console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
207    });
208} catch (errData) {
209    console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
210}
211```
212
213## launcherBundlemanager.getShortcutInfo<sup>9+</sup>
214
215getShortcutInfo(bundleName :string, callback: AsyncCallback<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>>) : void;
216
217Obtains the shortcut information of the current user based on the given bundle name. This API uses an asynchronous callback to return the result.
218
219**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
220
221**System API**: This is a system API.
222
223**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
224
225| Name    | Type  | Mandatory| Description        |
226| ---------- | ------ | ---- | -------------- |
227| bundleName | string | Yes  | Bundle name of the application.|
228
229**Return value**
230
231| Type                                                        | Description                                                        |
232| ------------------------------------------------------------ | ------------------------------------------------------------ |
233| AsyncCallback\<Array<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>> | Callback used to return the **ShortcutInfo** object obtained.|
234
235**Error codes**
236
237For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
238
239| ID| Error Message                               |
240| -------- | ---------------------------------------- |
241| 17700001 | The specified bundle name is not found.  |
242
243**Example**
244
245```ts
246import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
247
248try {
249    launcherBundleManager.getShortcutInfo("com.example.demo", (errData, data) => {
250        if (errData !== null) {
251            console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
252        }
253        console.log("data is " + JSON.stringify(data));
254    });
255} catch (errData) {
256    console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
257}
258```
259
260## launcherBundlemanager.getShortcutInfo<sup>9+</sup>
261
262getShortcutInfo(bundleName : string) : Promise<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>>;
263
264Obtains the shortcut information of the current user based on the given bundle name. This API uses a promise to return the result.
265
266**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
267
268**System API**: This is a system API.
269
270**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
271
272| Name    | Type  | Mandatory| Description        |
273| ---------- | ------ | ---- | -------------- |
274| bundleName | string | Yes  | Bundle name of the application.|
275
276**Return value**
277
278| Type                  | Description                                           |
279| ---------------------- | ----------------------------------------------- |
280| Promise\<Array<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>> | Promise used to return the **ShortcutInfo** object obtained.|
281
282**Error codes**
283
284For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
285
286| ID| Error Message                               |
287| -------- | ---------------------------------------- |
288| 17700001 | The specified bundle name is not found.  |
289
290**Example**
291
292```ts
293import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
294
295try {
296    launcherBundleManager.getShortcutInfo("com.example.demo").then(data => {
297        console.log("data is " + JSON.stringify(data));
298    }).catch (errData => {
299        console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
300    });
301} catch (errData) {
302    console.log(`errData is errCode:${errData.code}  message:${errData.message}`);
303}
304```
305