• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle.shortcutManager (shortcutManager)
2<!--Kit: Ability Kit-->
3<!--Subsystem: BundleManager-->
4<!--Owner: @wanghang904-->
5<!--Designer: @hanfeng6-->
6<!--Tester: @kongjing2-->
7<!--Adviser: @Brilliantry_Rui-->
8
9The module provides APIs to manage [shortcuts](../../quick-start/typical-scenario-configuration.md), including whether to display shortcuts.
10
11> **NOTE**
12>
13> The initial APIs of this module are supported since API version 20. Newly added APIs will be marked with a superscript to indicate their earliest API version.
14
15## Modules to Import
16
17```ts
18import { shortcutManager } from '@kit.AbilityKit';
19```
20
21## shortcutManager.setShortcutVisibleForSelf
22
23setShortcutVisibleForSelf(id: string, visible: boolean) : Promise\<void>
24
25Sets whether to display the specified shortcut for the current application. This API uses a promise to return the result.
26
27**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
28
29**Parameters**
30
31| Name    | Type  | Mandatory| Description        |
32| ---------- | ------ | ---- | -------------- |
33| id         | string | Yes  | Shortcut ID, which is the value of the **shortcutId** field under the **shortcuts** tag in the [module.json5](../../quick-start/module-configuration-file.md) file. The value is a string of up to 63 bytes.|
34| visible    | boolean| Yes  | Whether to display the shortcut. **true** to display, **false** otherwise.|
35
36**Return value**
37
38| Type            | Description             |
39| -------------- | --------------- |
40| Promise\<void> | Promise that returns no value.|
41
42**Error codes**
43
44For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md).
45
46| ID| Error Message                                |
47| -------- | ---------------------------------------- |
48| 17700070 | The specified shortcut id is illegal. |
49
50**Example**
51
52```ts
53import { shortcutManager } from '@kit.AbilityKit';
54import { BusinessError } from '@kit.BasicServicesKit';
55
56// Replace it with the shortcutId field under the shortcuts tag of the module.json5 file.
57shortcutManager.setShortcutVisibleForSelf("shortcut_id", false)
58  .then(() => {
59    console.info('setShortcutVisibleForSelf success');
60  }).catch((err: BusinessError) => {
61  console.error(`setShortcutVisibleForSelf errData is errCode:${err.code}  message:${err.message}`);
62});
63```
64
65## shortcutManager.getAllShortcutInfoForSelf
66
67getAllShortcutInfoForSelf(): Promise\<Array\<ShortcutInfo>>
68
69Obtains all the shortcut information defined in the [configuration](../../quick-start/module-configuration-file.md#shortcuts) file of the current application. This API uses a promise to return the result.
70
71**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
72
73**Return value**
74
75| Type                                                        | Description                                                        |
76| ------------------------------------------------------------ | ------------------------------------------------------------ |
77| Promise<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>> | Promise that returns all the shortcut information defined in the configuration file.|
78
79**Example**
80
81```ts
82import { shortcutManager } from '@kit.AbilityKit';
83import { BusinessError } from '@kit.BasicServicesKit';
84
85shortcutManager.getAllShortcutInfoForSelf()
86  .then((data: shortcutManager.ShortcutInfo[]) => {
87    console.info('getAllShortcutInfoForSelf shortcut data is' + JSON.stringify(data));
88  }).catch((err: BusinessError) => {
89    console.error(`getAllShortcutInfoForSelf errData is errCode:${err.code}  message:${err.message}`);
90  });
91```
92## ShortcutInfo
93
94type ShortcutInfo = _ShortcutInfo
95
96Defines the shortcut information defined in the [module.json5](../../quick-start/module-configuration-file.md#shortcuts) file of the application.
97
98**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
99
100| Type                                                        | Description          |
101| ------------------------------------------------------------ | -------------- |
102| [_ShortcutInfo](./js-apis-bundleManager-shortcutInfo.md#shortcutinfo-1) | Shortcut information defined in the configuration file.|
103
104## ShortcutWant
105
106type ShortcutWant = _ShortcutWant
107
108Defines the target [wants](../../quick-start/module-configuration-file.md#wants) defined in the shortcut configuration.
109
110**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
111
112| Type                                                        | Description          |
113| ------------------------------------------------------------ | -------------- |
114| [_ShortcutWant](./js-apis-bundleManager-shortcutInfo.md#shortcutwant) | Target [wants](../../quick-start/module-configuration-file.md#wants) defined in the shortcut configuration.|
115
116## ParameterItem
117
118type ParameterItem = _ParameterItem
119
120Defines the custom data in the shortcut configuration.
121
122**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
123
124| Type                                                        | Description          |
125| ------------------------------------------------------------ | -------------- |
126| [_ParameterItem](./js-apis-bundleManager-shortcutInfo.md#parameteritem) | Custom data in the shortcut configuration.|
127