1# @ohos.bundle.launcherBundleManager (launcherBundleManager模块) 2 3本模块支持launcher应用所需的查询能力,支持[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)、[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)信息的查询。 4 5> **说明:** 6> 7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9## 导入模块 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 20查询指定bundleName及用户的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。 21 22**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 23 24**系统接口:** 此接口为系统接口。 25 26**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher 27 28**参数:** 29 30| 参数名 | 类型 | 必填 | 说明 | 31| ---------- | ------ | ---- | -------------- | 32| bundleName | string | 是 | 应用Bundle名称。 | 33| userId | number | 是 | 被查询的用户id。| 34| callback | AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | 是 | callback形式返回bundle包含的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)信息。 | 35 36**错误码:** 37 38以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 39 40| 错误码ID | 错误信息 | 41| -------- | ---------------------------------------- | 42| 17700001 | The specified bundle name is not found. | 43| 17700004 | The specified user ID is not found. | 44 45**示例:** 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 71查询指定bundleName及用户的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。 72 73**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 74 75**系统接口:** 此接口为系统接口。 76 77**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher 78 79**参数:** 80 81| 参数名 | 类型 | 必填 | 说明 | 82| ---------- | ------ | ---- | -------------- | 83| bundleName | string | 是 | 应用Bundle名称。 | 84| userId | number | 是 | 被查询的用户id。 | 85 86**返回值:** 87 88| 类型 | 说明 | 89| ----------------------------- | -------------------------------------------------- | 90| Promise\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Promise形式返回bundle包含的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)信息。 | 91 92**错误码:** 93 94以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 95 96| 错误码ID | 错误信息 | 97| -------- | ---------------------------------------- | 98| 17700001 | The specified bundle name is not found. | 99| 17700004 | The specified user ID is not found. | 100 101**示例:** 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 125查询指定bundleName及用户的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。 126 127**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 128 129**系统接口:** 此接口为系统接口。 130 131**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher 132 133**参数:** 134 135| 参数名 | 类型 | 必填 | 说明 | 136| ---------- | ------ | ---- | -------------- | 137| bundleName | string | 是 | 应用Bundle名称。 | 138| userId | number | 是 | 被查询的用户id。 | 139 140**返回值:** 141 142| 类型 | 说明 | 143| ----------------------------- | -------------------------------------------------- | 144| Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)> | Array形式返回bundle包含的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)信息。 | 145 146**错误码:** 147 148以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 149 150| 错误码ID | 错误信息 | 151| -------- | ---------------------------------------- | 152| 17700001 | The specified bundle name is not found. | 153| 17700004 | The specified user ID is not found. | 154 155**示例:** 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 175查询指定用户下所有应用的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md) 176 177**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 178 179**系统接口:** 此接口为系统接口。 180 181**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher 182 183**参数:** 184 185| 参数名 | 类型 | 必填 | 说明 | 186| ------ | ------ | ---- | -------------- | 187| userId | number | 是 | 被查询的用户id。 | 188| callback | AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | 是 | callback形式返回指定用户下所有应用的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。 | 189 190**错误码:** 191 192以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 193 194| 错误码ID | 错误信息 | 195| -------- | ---------------------------------------- | 196| 17700004 | The specified user ID is not found. | 197 198示例: 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 223查询指定用户下所有应用的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。 224 225**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 226 227**系统接口:** 此接口为系统接口。 228 229**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher 230 231**参数:** 232 233| 参数名 | 类型 | 必填 | 说明 | 234| ------ | ------ | ---- | -------------- | 235| userId | number | 是 | 被查询的用户id。 | 236 237**返回值:** 238 239| 类型 | 说明 | 240| ----------------------------- | ------------------------------------------------------ | 241| Promise\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Promise形式返回指定用户下所有应用的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。 | 242 243**错误码:** 244 245以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 246 247| 错误码ID | 错误信息 | 248| -------- | ---------------------------------------- | 249| 17700004 | The specified user ID is not found. | 250 251**示例:** 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 275查询当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)。 276 277**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 278 279**系统接口:** 此接口为系统接口。 280 281**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher 282 283**参数:** 284 285| 参数名 | 类型 | 必填 | 说明 | 286| ---------- | ------ | ---- | -------------- | 287| bundleName | string | 是 | 应用Bundle名称。 | 288| callback | AsyncCallback\<Array<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>> | 是 | callback形式返回当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)。 | 289 290**错误码:** 291 292以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 293 294| 错误码ID | 错误信息 | 295| -------- | ---------------------------------------- | 296| 17700001 | The specified bundle name is not found. | 297 298**示例:** 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 324查询当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)。 325 326**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 327 328**系统接口:** 此接口为系统接口。 329 330**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher 331 332**参数:** 333 334| 参数名 | 类型 | 必填 | 说明 | 335| ---------- | ------ | ---- | -------------- | 336| bundleName | string | 是 | 应用Bundle名称。 | 337 338**返回值:** 339 340| 类型 | 说明 | 341| ---------------------- | ----------------------------------------------- | 342| Promise\<Array<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>> | Promise形式返回当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)。 | 343 344**错误码:** 345 346以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 347 348| 错误码ID | 错误信息 | 349| -------- | ---------------------------------------- | 350| 17700001 | The specified bundle name is not found. | 351 352**示例:** 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 376查询当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)。 377 378**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 379 380**系统接口:** 此接口为系统接口。 381 382**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher 383 384**参数:** 385 386| 参数名 | 类型 | 必填 | 说明 | 387| ---------- | ------ | ---- | -------------- | 388| bundleName | string | 是 | 应用Bundle名称。 | 389 390**返回值:** 391 392| 类型 | 说明 | 393| ---------------------- | ----------------------------------------------- | 394| Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)> | Array形式返回当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)。 | 395 396**错误码:** 397 398以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 399 400| 错误码ID | 错误信息 | 401| -------- | ---------------------------------------- | 402| 17700001 | The specified bundle name is not found. | 403 404**示例:** 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