• 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](js-apis-bundleManager-launcherAbilityInfo.md) and [shortcut information](js-apis-bundleManager-shortcutInfo.md).
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.|
33| userId     | number | Yes  | User ID.|
34| callback | AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Yes| Callback used to return the **LauncherAbilityInfo** object obtained.|
35
36**Error codes**
37
38For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
39
40| ID| Error Message                                |
41| -------- | ---------------------------------------- |
42| 17700001 | The specified bundle name is not found.  |
43| 17700004 | The specified user ID is not found.      |
44
45**Example**
46
47```ts
48import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
49import { BusinessError } from '@ohos.base';
50
51try {
52    launcherBundleManager.getLauncherAbilityInfo('com.example.demo', 100,
53        (errData: BusinessError, data: launcherBundleManager.LauncherAbilityInfo[]) => {
54        if (errData !== null) {
55            console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
56        } else {
57            console.log("data is " + JSON.stringify(data));
58        }
59    })
60} catch (errData) {
61    let code = (errData as BusinessError).code;
62    let message = (errData as BusinessError).message;
63    console.error(`errData is errCode:${code}  message:${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.|
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 user ID is not found.       |
100
101**Example**
102
103```ts
104import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
105import { BusinessError } from '@ohos.base';
106
107try {
108    launcherBundleManager.getLauncherAbilityInfo("com.example.demo", 100)
109        .then((data: launcherBundleManager.LauncherAbilityInfo[]) => {
110        console.log("data is " + JSON.stringify(data));
111    }).catch ((errData: BusinessError) => {
112        console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
113    })
114} catch (errData) {
115    let code = (errData as BusinessError).code;
116    let message = (errData as BusinessError).message;
117    console.error(`errData is errCode:${code}  message:${message}`);
118}
119```
120
121## launcherBundleManager.getLauncherAbilityInfoSync<sup>10+</sup>
122
123getLauncherAbilityInfoSync(bundleName: string, userId: number) : Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>
124
125Obtains the launcher ability information based on the given bundle name and user ID. This API returns the result synchronously.
126
127**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
128
129**System API**: This is a system API.
130
131**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
132
133**Parameters**
134
135| Name    | Type  | Mandatory| Description        |
136| ---------- | ------ | ---- | -------------- |
137| bundleName | string | Yes  | Bundle name.|
138| userId     | number | Yes  | User ID.|
139
140**Return value**
141
142| Type                         | Description                                              |
143| ----------------------------- | -------------------------------------------------- |
144| Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)> | Array of the **LauncherAbilityInfo** objects obtained.|
145
146**Error codes**
147
148For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
149
150| ID| Error Message                                |
151| -------- | ---------------------------------------- |
152| 17700001 | The specified bundle name is not found.  |
153| 17700004 | The specified user ID is not found.       |
154
155**Example**
156
157```ts
158import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
159import { BusinessError } from '@ohos.base';
160
161try {
162    let data = launcherBundleManager.getLauncherAbilityInfoSync("com.example.demo", 100);
163    console.log("data is " + JSON.stringify(data));
164} catch (errData) {
165    let code = (errData as BusinessError).code;
166    let message = (errData as BusinessError).message;
167    console.error(`errData is errCode:${code}  message:${message}`);
168}
169```
170
171## launcherBundleManager.getAllLauncherAbilityInfo<sup>9+</sup>
172
173getAllLauncherAbilityInfo(userId: number, callback: AsyncCallback<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>>) : void
174
175Obtains the launcher ability information of all applications based on the given user ID. This API uses an asynchronous callback to return the result.
176
177**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
178
179**System API**: This is a system API.
180
181**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
182
183**Parameters**
184
185| Name| Type  | Mandatory| Description        |
186| ------ | ------ | ---- | -------------- |
187| userId | number | Yes  | User ID.|
188| callback | AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Yes| Callback used to return the array of **LauncherAbilityInfo** objects obtained.|
189
190**Error codes**
191
192For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
193
194| ID| Error Message                               |
195| -------- | ---------------------------------------- |
196| 17700004 | The specified user ID is not found.      |
197
198Example
199
200```ts
201import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
202import { BusinessError } from '@ohos.base';
203
204try {
205    launcherBundleManager.getAllLauncherAbilityInfo(100,
206        (errData: BusinessError, data: launcherBundleManager.LauncherAbilityInfo[]) => {
207        if (errData !== null) {
208            console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
209        } else {
210            console.log("data is " + JSON.stringify(data));
211        }
212    });
213} catch (errData) {
214    let code = (errData as BusinessError).code;
215    let message = (errData as BusinessError).message;
216    console.error(`errData is errCode:${code}  message:${message}`);
217}
218```
219## launcherBundleManager.getAllLauncherAbilityInfo<sup>9+</sup>
220
221getAllLauncherAbilityInfo(userId: number) : Promise<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>>
222
223Obtains the launcher ability information of all applications based on the given user ID. This API uses a promise to return the result.
224
225**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
226
227**System API**: This is a system API.
228
229**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
230
231**Parameters**
232
233| Name| Type  | Mandatory| Description        |
234| ------ | ------ | ---- | -------------- |
235| userId | number | Yes  | User ID.|
236
237**Return value**
238
239| Type                         | Description                                                  |
240| ----------------------------- | ------------------------------------------------------ |
241| Promise\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Promise used to return the array of **LauncherAbilityInfo** objects obtained.|
242
243**Error codes**
244
245For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
246
247| ID| Error Message                               |
248| -------- | ---------------------------------------- |
249| 17700004 | The specified user ID is not found.      |
250
251**Example**
252
253```ts
254import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
255import { BusinessError } from '@ohos.base';
256
257try {
258    launcherBundleManager.getAllLauncherAbilityInfo(100)
259        .then((data: launcherBundleManager.LauncherAbilityInfo[]) => {
260        console.log("data is " + JSON.stringify(data));
261    }).catch ((errData: BusinessError) => {
262        console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
263    });
264} catch (errData) {
265    let code = (errData as BusinessError).code;
266    let message = (errData as BusinessError).message;
267    console.error(`errData is errCode:${code}  message:${message}`);
268}
269```
270
271## launcherBundleManager.getShortcutInfo<sup>9+</sup>
272
273getShortcutInfo(bundleName :string, callback: AsyncCallback<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>>) : void
274
275Obtains the shortcut information of the current user based on the given bundle name. This API uses an asynchronous callback to return the result.
276
277**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
278
279**System API**: This is a system API.
280
281**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
282
283**Parameters**
284
285| Name    | Type  | Mandatory| Description        |
286| ---------- | ------ | ---- | -------------- |
287| bundleName | string | Yes  | Bundle name.|
288| callback | AsyncCallback\<Array<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>> | Yes| Callback used to return the **ShortcutInfo** object obtained.|
289
290**Error codes**
291
292For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
293
294| ID| Error Message                               |
295| -------- | ---------------------------------------- |
296| 17700001 | The specified bundle name is not found.  |
297
298**Example**
299
300```ts
301import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
302import { BusinessError } from '@ohos.base';
303
304try {
305    launcherBundleManager.getShortcutInfo("com.example.demo",
306        (errData: BusinessError, data: launcherBundleManager.ShortcutInfo[]) => {
307        if (errData !== null) {
308            console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
309        } else {
310            console.log("data is " + JSON.stringify(data));
311        }
312    });
313} catch (errData) {
314    let code = (errData as BusinessError).code;
315    let message = (errData as BusinessError).message;
316    console.error(`errData is errCode:${code}  message:${message}`);
317}
318```
319
320## launcherBundleManager.getShortcutInfo<sup>9+</sup>
321
322getShortcutInfo(bundleName : string) : Promise<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>>
323
324Obtains the shortcut information of the current user based on the given bundle name. This API uses a promise to return the result.
325
326**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
327
328**System API**: This is a system API.
329
330**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
331
332**Parameters**
333
334| Name    | Type  | Mandatory| Description        |
335| ---------- | ------ | ---- | -------------- |
336| bundleName | string | Yes  | Bundle name.|
337
338**Return value**
339
340| Type                  | Description                                           |
341| ---------------------- | ----------------------------------------------- |
342| Promise\<Array<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>> | Promise used to return the **ShortcutInfo** object obtained.|
343
344**Error codes**
345
346For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
347
348| ID| Error Message                               |
349| -------- | ---------------------------------------- |
350| 17700001 | The specified bundle name is not found.  |
351
352**Example**
353
354```ts
355import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
356import { BusinessError } from '@ohos.base';
357
358try {
359    launcherBundleManager.getShortcutInfo("com.example.demo")
360        .then((data: launcherBundleManager.ShortcutInfo[]) => {
361        console.log("data is " + JSON.stringify(data));
362    }).catch ((errData: BusinessError) => {
363        console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
364    });
365} catch (errData) {
366    let code = (errData as BusinessError).code;
367    let message = (errData as BusinessError).message;
368    console.error(`errData is errCode:${code}  message:${message}`);
369}
370```
371
372## launcherBundleManager.getShortcutInfoSync<sup>10+</sup>
373
374getShortcutInfoSync(bundleName : string) : Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>
375
376Obtains the shortcut information of the current user based on the given bundle name. This API returns the result synchronously.
377
378**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
379
380**System API**: This is a system API.
381
382**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
383
384**Parameters**
385
386| Name    | Type  | Mandatory| Description        |
387| ---------- | ------ | ---- | -------------- |
388| bundleName | string | Yes  | Bundle name.|
389
390**Return value**
391
392| Type                  | Description                                           |
393| ---------------------- | ----------------------------------------------- |
394| Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)> | Array of the **ShortcutInfo** objects obtained.|
395
396**Error codes**
397
398For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
399
400| ID| Error Message                               |
401| -------- | ---------------------------------------- |
402| 17700001 | The specified bundle name is not found.  |
403
404**Example**
405
406```ts
407import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
408import { BusinessError } from '@ohos.base';
409
410try {
411    let data = launcherBundleManager.getShortcutInfoSync("com.example.demo");
412    console.log("data is " + JSON.stringify(data));
413} catch (errData) {
414    let code = (errData as BusinessError).code;
415    let message = (errData as BusinessError).message;
416    console.error(`errData is errCode:${code}  message:${message}`);
417}
418```
419