• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle.launcherBundleManager (launcherBundleManager模块)(系统接口)
2
3本模块支持launcher应用所需的查询能力,支持[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)、[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)信息的查询。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 本模块为系统接口。
10
11## 导入模块
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.md)\>\>) : void
21
22查询指定bundleName及用户的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。
23
24**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
25
26**系统接口:** 此接口为系统接口。
27
28**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
29
30**参数:**
31
32| 参数名     | 类型   | 必填 | 说明         |
33| ---------- | ------ | ---- | -------------- |
34| bundleName | string | 是   | 应用Bundle名称。 |
35| userId     | number | 是   | 被查询的用户id。|
36| callback | AsyncCallback\<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)\>\> | 是 | callback形式返回bundle包含的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)信息。 |
37
38**错误码:**
39
40以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
41
42| 错误码ID | 错误信息                                 |
43| -------- | ---------------------------------------- |
44| 201 | Verify permission denied. |
45| 202 | Permission denied, non-system app called system api. |
46| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
47| 801 | Capability not support. |
48| 17700001 | The specified bundle name is not found.  |
49| 17700004 | The specified user ID is not found.      |
50
51**示例:**
52
53```ts
54import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
55import { BusinessError } from '@ohos.base';
56
57try {
58    launcherBundleManager.getLauncherAbilityInfo('com.example.demo', 100,
59        (errData: BusinessError, data: launcherBundleManager.LauncherAbilityInfo[]) => {
60        if (errData !== null) {
61            console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
62        } else {
63            console.log("data is " + JSON.stringify(data));
64        }
65    })
66} catch (errData) {
67    let code = (errData as BusinessError).code;
68    let message = (errData as BusinessError).message;
69    console.error(`errData is errCode:${code}  message:${message}`);
70}
71```
72
73## launcherBundleManager.getLauncherAbilityInfo<sup>9+</sup>
74
75getLauncherAbilityInfo(bundleName: string, userId: number) : Promise\<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)\>\>
76
77查询指定bundleName及用户的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。
78
79**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
80
81**系统接口:** 此接口为系统接口。
82
83**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
84
85**参数:**
86
87| 参数名     | 类型   | 必填 | 说明         |
88| ---------- | ------ | ---- | -------------- |
89| bundleName | string | 是   | 应用Bundle名称。 |
90| userId     | number | 是   | 被查询的用户id。 |
91
92**返回值:**
93
94| 类型                          | 说明                                               |
95| ----------------------------- | -------------------------------------------------- |
96| Promise\<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)\>\> | Promise形式返回bundle包含的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)信息。 |
97
98**错误码:**
99
100以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
101
102| 错误码ID | 错误信息                                 |
103| -------- | ---------------------------------------- |
104| 201 | Verify permission denied. |
105| 202 | Permission denied, non-system app called system api. |
106| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
107| 801 | Capability not support. |
108| 17700001 | The specified bundle name is not found.  |
109| 17700004 | The specified user ID is not found.       |
110
111**示例:**
112
113```ts
114import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
115import { BusinessError } from '@ohos.base';
116
117try {
118    launcherBundleManager.getLauncherAbilityInfo("com.example.demo", 100)
119        .then((data: launcherBundleManager.LauncherAbilityInfo[]) => {
120        console.log("data is " + JSON.stringify(data));
121    }).catch ((errData: BusinessError) => {
122        console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
123    })
124} catch (errData) {
125    let code = (errData as BusinessError).code;
126    let message = (errData as BusinessError).message;
127    console.error(`errData is errCode:${code}  message:${message}`);
128}
129```
130
131## launcherBundleManager.getAllLauncherAbilityInfo<sup>9+</sup>
132
133getAllLauncherAbilityInfo(userId: number, callback: AsyncCallback\<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)\>\>) : void
134
135查询指定用户下所有应用的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。
136
137**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
138
139**系统接口:** 此接口为系统接口。
140
141**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
142
143**参数:**
144
145| 参数名 | 类型   | 必填 | 说明         |
146| ------ | ------ | ---- | -------------- |
147| userId | number | 是   | 被查询的用户id。 |
148| callback | AsyncCallback\<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)\>\> | 是 | callback形式返回指定用户下所有应用的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。 |
149
150**错误码:**
151
152以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
153
154| 错误码ID | 错误信息                                |
155| -------- | ---------------------------------------- |
156| 201 | Verify permission denied. |
157| 202 | Permission denied, non-system app called system api. |
158| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
159| 801 | Capability not support. |
160| 17700004 | The specified user ID is not found.      |
161
162示例:
163
164```ts
165import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
166import { BusinessError } from '@ohos.base';
167
168try {
169    launcherBundleManager.getAllLauncherAbilityInfo(100,
170        (errData: BusinessError, data: launcherBundleManager.LauncherAbilityInfo[]) => {
171        if (errData !== null) {
172            console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
173        } else {
174            console.log("data is " + JSON.stringify(data));
175        }
176    });
177} catch (errData) {
178    let code = (errData as BusinessError).code;
179    let message = (errData as BusinessError).message;
180    console.error(`errData is errCode:${code}  message:${message}`);
181}
182```
183## launcherBundleManager.getAllLauncherAbilityInfo<sup>9+</sup>
184
185getAllLauncherAbilityInfo(userId: number) : Promise\<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)\>\>
186
187查询指定用户下所有应用的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。
188
189**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
190
191**系统接口:** 此接口为系统接口。
192
193**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
194
195**参数:**
196
197| 参数名 | 类型   | 必填 | 说明         |
198| ------ | ------ | ---- | -------------- |
199| userId | number | 是   | 被查询的用户id。 |
200
201**返回值:**
202
203| 类型                          | 说明                                                   |
204| ----------------------------- | ------------------------------------------------------ |
205| Promise\<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)\>\> | Promise形式返回指定用户下所有应用的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。 |
206
207**错误码:**
208
209以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
210
211| 错误码ID | 错误信息                                |
212| -------- | ---------------------------------------- |
213| 201 | Verify permission denied. |
214| 202 | Permission denied, non-system app called system api. |
215| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
216| 801 | Capability not support. |
217| 17700004 | The specified user ID is not found.      |
218
219**示例:**
220
221```ts
222import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
223import { BusinessError } from '@ohos.base';
224
225try {
226    launcherBundleManager.getAllLauncherAbilityInfo(100)
227        .then((data: launcherBundleManager.LauncherAbilityInfo[]) => {
228        console.log("data is " + JSON.stringify(data));
229    }).catch ((errData: BusinessError) => {
230        console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
231    });
232} catch (errData) {
233    let code = (errData as BusinessError).code;
234    let message = (errData as BusinessError).message;
235    console.error(`errData is errCode:${code}  message:${message}`);
236}
237```
238
239## launcherBundleManager.getShortcutInfo<sup>9+</sup>
240
241getShortcutInfo(bundleName :string, callback: AsyncCallback\<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)\>\>) : void
242
243查询当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)。
244
245**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
246
247**系统接口:** 此接口为系统接口。
248
249**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
250
251**参数:**
252
253| 参数名     | 类型   | 必填 | 说明         |
254| ---------- | ------ | ---- | -------------- |
255| bundleName | string | 是   | 应用Bundle名称。 |
256| callback | AsyncCallback\<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)\>\> | 是 | callback形式返回当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)。 |
257
258**错误码:**
259
260以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
261
262| 错误码ID | 错误信息                                |
263| -------- | ---------------------------------------- |
264| 201 | Verify permission denied. |
265| 202 | Permission denied, non-system app called system api. |
266| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
267| 801 | Capability not support. |
268| 17700001 | The specified bundle name is not found.  |
269
270**示例:**
271
272```ts
273import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
274import { BusinessError } from '@ohos.base';
275
276try {
277    launcherBundleManager.getShortcutInfo("com.example.demo",
278        (errData: BusinessError, data: launcherBundleManager.ShortcutInfo[]) => {
279        if (errData !== null) {
280            console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
281        } else {
282            console.log("data is " + JSON.stringify(data));
283        }
284    });
285} catch (errData) {
286    let code = (errData as BusinessError).code;
287    let message = (errData as BusinessError).message;
288    console.error(`errData is errCode:${code}  message:${message}`);
289}
290```
291
292## launcherBundleManager.getShortcutInfo<sup>9+</sup>
293
294getShortcutInfo(bundleName : string) : Promise\<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)\>\>
295
296查询当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)。
297
298**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
299
300**系统接口:** 此接口为系统接口。
301
302**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
303
304**参数:**
305
306| 参数名     | 类型   | 必填 | 说明         |
307| ---------- | ------ | ---- | -------------- |
308| bundleName | string | 是   | 应用Bundle名称。 |
309
310**返回值:**
311
312| 类型                   | 说明                                            |
313| ---------------------- | ----------------------------------------------- |
314| Promise\<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)\>\> | Promise形式返回当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)。 |
315
316**错误码:**
317
318以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
319
320| 错误码ID | 错误信息                                |
321| -------- | ---------------------------------------- |
322| 201 | Verify permission denied. |
323| 202 | Permission denied, non-system app called system api. |
324| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
325| 801 | Capability not support. |
326| 17700001 | The specified bundle name is not found.  |
327
328**示例:**
329
330```ts
331import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
332import { BusinessError } from '@ohos.base';
333
334try {
335    launcherBundleManager.getShortcutInfo("com.example.demo")
336        .then((data: launcherBundleManager.ShortcutInfo[]) => {
337        console.log("data is " + JSON.stringify(data));
338    }).catch ((errData: BusinessError) => {
339        console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
340    });
341} catch (errData) {
342    let code = (errData as BusinessError).code;
343    let message = (errData as BusinessError).message;
344    console.error(`errData is errCode:${code}  message:${message}`);
345}
346```
347
348## launcherBundleManager.getShortcutInfoSync<sup>10+</sup>
349
350getShortcutInfoSync(bundleName : string) : Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)\>
351
352查询当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)。
353
354**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
355
356**系统接口:** 此接口为系统接口。
357
358**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
359
360**参数:**
361
362| 参数名     | 类型   | 必填 | 说明         |
363| ---------- | ------ | ---- | -------------- |
364| bundleName | string | 是   | 应用Bundle名称。 |
365
366**返回值:**
367
368| 类型                   | 说明                                            |
369| ---------------------- | ----------------------------------------------- |
370| Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)\> | Array形式返回当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)。 |
371
372**错误码:**
373
374以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
375
376| 错误码ID | 错误信息                                |
377| -------- | ---------------------------------------- |
378| 201 | Verify permission denied. |
379| 202 | Permission denied, non-system app called system api. |
380| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
381| 801 | Capability not support. |
382| 17700001 | The specified bundle name is not found.  |
383
384**示例:**
385
386```ts
387import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
388import { BusinessError } from '@ohos.base';
389
390try {
391    let data = launcherBundleManager.getShortcutInfoSync("com.example.demo");
392    console.log("data is " + JSON.stringify(data));
393} catch (errData) {
394    let code = (errData as BusinessError).code;
395    let message = (errData as BusinessError).message;
396    console.error(`errData is errCode:${code}  message:${message}`);
397}
398```
399
400## launcherBundleManager.getShortcutInfoSync<sup>13+</sup>
401
402getShortcutInfoSync(bundleName: string, userId: number) : Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)\>
403
404查询指定用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)。
405
406**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
407
408**系统接口:** 此接口为系统接口。
409
410**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
411
412**参数:**
413
414| 参数名     | 类型   | 必填 | 说明         |
415| ---------- | ------ | ---- | -------------- |
416| bundleName | string | 是   | 应用Bundle名称。 |
417| userId     | number | 是   | 表示用户ID。  |
418
419**返回值:**
420
421| 类型                   | 说明                                            |
422| ---------------------- | ----------------------------------------------- |
423| Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)\> | Array形式返回指定用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)。 |
424
425**错误码:**
426
427以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
428
429| 错误码ID | 错误信息                                |
430| -------- | ---------------------------------------- |
431| 201 | Verify permission denied. |
432| 202 | Permission denied, non-system app called system api. |
433| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
434| 801 | Capability not support. |
435| 17700001 | The specified bundle name is not found.  |
436| 17700004 | The specified user ID is not found.     |
437
438**示例:**
439
440```ts
441import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
442import { BusinessError } from '@ohos.base';
443
444try {
445    let data = launcherBundleManager.getShortcutInfoSync("com.example.demo", 100);
446    console.log("data is " + JSON.stringify(data));
447} catch (errData) {
448    let code = (errData as BusinessError).code;
449    let message = (errData as BusinessError).message;
450    console.error(`errData is errCode:${code}  message:${message}`);
451}
452```
453
454## launcherBundleManager.startShortcut<sup>12+</sup>
455
456startShortcut(shortcutInfo: ShortcutInfo, options?: StartOptions): Promise\<void\>;
457
458拉起指定[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)中的ability。
459
460**需要权限:** ohos.permission.START_SHORTCUT
461
462**系统接口:** 此接口为系统接口。
463
464**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
465
466**参数:**
467
468| 参数名        | 类型   | 必填 | 说明         |
469| ------------ | ------ | ---- | -------------- |
470| shortcutInfo | [ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md) | 是   | 应用的快捷方式信息。 |
471| options      | [StartOptions](js-apis-app-ability-startOptions-sys.md)   | 否   | 启动参数选项,用于指定任务切到前台时的窗口模式,设备ID等。 |
472
473**错误码:**
474
475以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
476
477| 错误码ID | 错误信息                                |
478| -------- | ---------------------------------------- |
479| 201 | Verify permission denied. |
480| 202 | Permission denied, non-system app called system api. |
481| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
482| 801 | Capability not support. |
483| 17700065 | The ability specified by want in the ShortcutInfo struct cannot be started.  |
484
485**示例:**
486
487```ts
488import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
489import { BusinessError } from '@ohos.base';
490
491try {
492    let data : Array<launcherBundleManager.ShortcutInfo> = launcherBundleManager.getShortcutInfoSync("com.example.demo");
493    console.log("data is " + JSON.stringify(data));
494    if (data) {
495        try {
496            launcherBundleManager.startShortcut(data[0])
497                .then(() => {
498                console.log("startShortcut success");
499            }).catch ((err: BusinessError) => {
500                console.error(`errData is errCode:${err.code}  message:${err.message}`);
501            });
502        } catch (error) {
503            let code = (error as BusinessError).code;
504            let message = (error as BusinessError).message;
505            console.error(`error is errCode:${code}  message:${message}`);
506        }
507    }
508} catch (errData) {
509    let code = (errData as BusinessError).code;
510    let message = (errData as BusinessError).message;
511    console.error(`errData is errCode:${code}  message:${message}`);
512}
513```
514