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