1e41f4b71Sopenharmony_ci# @ohos.bundle.shortcutManager (shortcutManager) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe shortcutManager module allows system applications to add, delete, and query shortcuts, including [ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md).
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> The APIs provided by this module are system APIs.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Modules to Import
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```ts
14e41f4b71Sopenharmony_ciimport { shortcutManager } from '@kit.AbilityKit';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci## shortcutManager.addDesktopShortcutInfo<sup>12+</sup>
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ciaddDesktopShortcutInfo(shortcutInfo: [ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md), userId: number) : Promise\<void>
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ciAdds [ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md) for a given user.
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_SHORTCUTS
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**System API**: This is a system API.
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci**Parameters**
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci| Name    | Type  | Mandatory| Description        |
33e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | -------------- |
34e41f4b71Sopenharmony_ci| shortcutInfo | [ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md) | Yes  | Shortcut information.|
35e41f4b71Sopenharmony_ci| userId     | number | Yes  | User ID.|
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**Error codes**
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci| ID| Error Message                                |
42e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
43e41f4b71Sopenharmony_ci| 201 | Verify permission denied. |
44e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
45e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
46e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found.  |
47e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.      |
48e41f4b71Sopenharmony_ci| 17700026 | The specified bundle is disabled. |
49e41f4b71Sopenharmony_ci| 17700061 | The specified app index is invalid. |
50e41f4b71Sopenharmony_ci| 17700070 | The specified shortcut id is illegal. |
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci**Example**
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci```ts
55e41f4b71Sopenharmony_ciimport { shortcutManager } from '@kit.AbilityKit';
56e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci@Entry
59e41f4b71Sopenharmony_ci@Component
60e41f4b71Sopenharmony_cistruct ShortcutExample {
61e41f4b71Sopenharmony_ci  build() {
62e41f4b71Sopenharmony_ci    Column({ space: 20 }) {
63e41f4b71Sopenharmony_ci      Row({ space: 20 }) {
64e41f4b71Sopenharmony_ci        Button('add').onClick(() => {
65e41f4b71Sopenharmony_ci          let data: shortcutManager.ShortcutInfo = {
66e41f4b71Sopenharmony_ci            id: "test1",
67e41f4b71Sopenharmony_ci            bundleName: "com.example.myapplication",
68e41f4b71Sopenharmony_ci            moduleName: "hello",
69e41f4b71Sopenharmony_ci            hostAbility: "hello",
70e41f4b71Sopenharmony_ci            icon: "hello",
71e41f4b71Sopenharmony_ci            iconId: 1,
72e41f4b71Sopenharmony_ci            label: "hello",
73e41f4b71Sopenharmony_ci            labelId: 1,
74e41f4b71Sopenharmony_ci            wants: [],
75e41f4b71Sopenharmony_ci            appIndex: 0,
76e41f4b71Sopenharmony_ci            sourceType: 0,
77e41f4b71Sopenharmony_ci          }
78e41f4b71Sopenharmony_ci          try {
79e41f4b71Sopenharmony_ci            shortcutManager.addDesktopShortcutInfo(data, 100)
80e41f4b71Sopenharmony_ci              .then(() => {
81e41f4b71Sopenharmony_ci                console.log("addDesktopShortcutInfo success");
82e41f4b71Sopenharmony_ci              }).catch((err: BusinessError) => {
83e41f4b71Sopenharmony_ci              console.error(`addDesktopShortcutInfo errData is errCode:${err.code}  message:${err.message}`);
84e41f4b71Sopenharmony_ci            });
85e41f4b71Sopenharmony_ci          } catch (error) {
86e41f4b71Sopenharmony_ci            let code = (error as BusinessError).code;
87e41f4b71Sopenharmony_ci            let message = (error as BusinessError).message;
88e41f4b71Sopenharmony_ci            console.error(`addDesktopShortcutInfo error is errCode:${code}  message:${message}`);
89e41f4b71Sopenharmony_ci          }
90e41f4b71Sopenharmony_ci        })
91e41f4b71Sopenharmony_ci      }
92e41f4b71Sopenharmony_ci    }
93e41f4b71Sopenharmony_ci  }
94e41f4b71Sopenharmony_ci}
95e41f4b71Sopenharmony_ci```
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci## shortcutManager.deleteDesktopShortcutInfo<sup>12+</sup>
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_cideleteDesktopShortcutInfo(shortcutInfo: [ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md), userId: number) : Promise\<void>
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ciDeletes [ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md) for a given user.
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_SHORTCUTS
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci**System API**: This is a system API.
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci**Parameters**
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci| Name    | Type  | Mandatory| Description        |
112e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | -------------- |
113e41f4b71Sopenharmony_ci| shortcutInfo | [ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md) | Yes  | Shortcut information.|
114e41f4b71Sopenharmony_ci| userId     | number | Yes  | User ID.|
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci**Error codes**
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci| ID| Error Message                                |
121e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
122e41f4b71Sopenharmony_ci| 201 | Verify permission denied. |
123e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
124e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
125e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.       |
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**Example**
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci```ts
130e41f4b71Sopenharmony_ciimport { shortcutManager } from '@kit.AbilityKit';
131e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci@Entry
134e41f4b71Sopenharmony_ci@Component
135e41f4b71Sopenharmony_cistruct ShortcutExample {
136e41f4b71Sopenharmony_ci  build() {
137e41f4b71Sopenharmony_ci    Column({ space: 20 }) {
138e41f4b71Sopenharmony_ci      Row({ space: 20 }) {
139e41f4b71Sopenharmony_ci        Button('delete').onClick(() => {
140e41f4b71Sopenharmony_ci          let data: shortcutManager.ShortcutInfo = {
141e41f4b71Sopenharmony_ci            id: "test1",
142e41f4b71Sopenharmony_ci            bundleName: "com.example.myapplication",
143e41f4b71Sopenharmony_ci            moduleName: "",
144e41f4b71Sopenharmony_ci            hostAbility: "",
145e41f4b71Sopenharmony_ci            icon: "",
146e41f4b71Sopenharmony_ci            iconId: 1,
147e41f4b71Sopenharmony_ci            label: "hello",
148e41f4b71Sopenharmony_ci            labelId: 1,
149e41f4b71Sopenharmony_ci            wants: [],
150e41f4b71Sopenharmony_ci            appIndex: 0,
151e41f4b71Sopenharmony_ci            sourceType: 0,
152e41f4b71Sopenharmony_ci          }
153e41f4b71Sopenharmony_ci          try {
154e41f4b71Sopenharmony_ci            shortcutManager.deleteDesktopShortcutInfo(data, 100)
155e41f4b71Sopenharmony_ci              .then(() => {
156e41f4b71Sopenharmony_ci                console.log("deleteDesktopShortcutInfo success");
157e41f4b71Sopenharmony_ci              }).catch((err: BusinessError) => {
158e41f4b71Sopenharmony_ci              console.error(`deleteDesktopShortcutInfo errData is errCode:${err.code}  message:${err.message}`);
159e41f4b71Sopenharmony_ci            });
160e41f4b71Sopenharmony_ci          } catch (error) {
161e41f4b71Sopenharmony_ci            let code = (error as BusinessError).code;
162e41f4b71Sopenharmony_ci            let message = (error as BusinessError).message;
163e41f4b71Sopenharmony_ci            console.error(`deleteDesktopShortcutInfo error is errCode:${code}  message:${message}`);
164e41f4b71Sopenharmony_ci          }
165e41f4b71Sopenharmony_ci        })
166e41f4b71Sopenharmony_ci      }
167e41f4b71Sopenharmony_ci    }
168e41f4b71Sopenharmony_ci  }
169e41f4b71Sopenharmony_ci}
170e41f4b71Sopenharmony_ci```
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci## shortcutManager.getAllDesktopShortcutInfo<sup>12+</sup>
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_cigetAllDesktopShortcutInfo(userId: number) : Promise<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)>>
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ciObtains all [ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md) records of a given user.
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_SHORTCUTS
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci**System API**: This is a system API.
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci**Parameters**
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci| Name    | Type  | Mandatory| Description        |
187e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | -------------- |
188e41f4b71Sopenharmony_ci| userId     | number | Yes  | User ID.|
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci**Return value**
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci| Type                                                        | Description                                                        |
193e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ |
194e41f4b71Sopenharmony_ci| Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md)> | Array that holds the [ShortcutInfo](js-apis-bundleManager-shortcutInfo-sys.md) objects.|
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci**Error codes**
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci| ID| Error Message                                |
201e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
202e41f4b71Sopenharmony_ci| 201 | Verify permission denied. |
203e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
204e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
205e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.       |
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci**Example**
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci```ts
210e41f4b71Sopenharmony_ciimport { shortcutManager } from '@kit.AbilityKit';
211e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci@Entry
214e41f4b71Sopenharmony_ci@Component
215e41f4b71Sopenharmony_cistruct ShortcutExample {
216e41f4b71Sopenharmony_ci  build() {
217e41f4b71Sopenharmony_ci    Column({ space: 20 }) {
218e41f4b71Sopenharmony_ci      Row({ space: 20 }) {
219e41f4b71Sopenharmony_ci        Button('getall').onClick(() => {
220e41f4b71Sopenharmony_ci          try {
221e41f4b71Sopenharmony_ci            shortcutManager.getAllDesktopShortcutInfo(100)
222e41f4b71Sopenharmony_ci              .then((data: shortcutManager.ShortcutInfo[]) => {
223e41f4b71Sopenharmony_ci                console.log("Shortcut data is " + JSON.stringify(data));
224e41f4b71Sopenharmony_ci              }).catch((err: BusinessError) => {
225e41f4b71Sopenharmony_ci              console.error(`getAllDesktopShortcutInfo errData is errCode:${err.code}  message:${err.message}`);
226e41f4b71Sopenharmony_ci            });
227e41f4b71Sopenharmony_ci          } catch (error) {
228e41f4b71Sopenharmony_ci            let code = (error as BusinessError).code;
229e41f4b71Sopenharmony_ci            let message = (error as BusinessError).message;
230e41f4b71Sopenharmony_ci            console.error(`getAllDesktopShortcutInfo error is errCode:${code}  message:${message}`);
231e41f4b71Sopenharmony_ci          }
232e41f4b71Sopenharmony_ci        })
233e41f4b71Sopenharmony_ci      }
234e41f4b71Sopenharmony_ci    }
235e41f4b71Sopenharmony_ci  }
236e41f4b71Sopenharmony_ci}
237e41f4b71Sopenharmony_ci```
238