1# Bundle模块(JS端SDK接口) 2 3#### 支持设备 4 5| API | 手机 | 平板 | 智慧屏 | 智能穿戴 | 轻量级智能穿戴 | 智慧视觉设备 | 6| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ | 7| Bundle.getApplicationInfo(bundleName: string, bundleFlags: number, userId: number) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 8| Bundle.getApplicationInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback<ApplicationInfo>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 9| Bundle.getAllBundleInfo(bundlelFlag: BundleFlag) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 10| Bundle.getAllBundleInfo(bundlelFlag: BundleFlag, callback: AsyncCallback<Array<BundleInfo>>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 11| Bundle.getBundleInfo(bundleName: string, bundleFlags: number) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 12| Bundle.getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback<BundleInfo>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 13| Bundle.getAllApplicationInfo(bundleFlags: number, userId: number) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 14| Bundle.getAllApplicationInfo(bundleFlags: number, userId: number, callback: AsyncCallback<Array<ApplicationInfo>>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 15| Bundle.queryAbilityByWant(want: Want, bundleFlags: number, userId: number) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 16| Bundle.queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback<Array<AbilityInfo>>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 17| Bundle.getPermissionDef(permissionName: string) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 18| Bundle.getPermissionDef(permissionName: string, callback: AsyncCallback<permission.PermissionDef>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 19| Bundle.getBundleArchiveInfo(hapFilePath: string, flags: number) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 20| Bundle.getBundleArchiveInfo(hapFilePath: string, flags: number, callback: AsyncCallback<BundleInfo>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 21| Bundle.getBundleInstaller().install(bundleFilePaths: Array<string>, param: InstallParam, callback: AsyncCallback<InstallStatus>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 22| Bundle.getBundleInstaller().uninstall(bundleName: string, param: InstallParam, callback: AsyncCallback<InstallStatus>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 23| Bundle.getAllShortcutInfo(bundleName: string): Promise<Array<ShortcutInfo>> | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 24| Bundle.getAllShortcutInfo(bundleName: string, callback: AsyncCallback<Array<ShortcutInfo>>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 25| getModuleUsageRecords(maxNum: number): Promise<Array<ModuleUsageRecord>> | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 26| getModuleUsageRecords(maxNum: number, callback: AsyncCallback<Array<ModuleUsageRecord>>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 27| checkPermission(bundleName: string, permission: string): Promise<GrantStatus> | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 28| checkPermission(bundleName: string, permission: string, callback: AsyncCallback<GrantStatus>) | 支持 | 支持 | 支持 | 支持 | 不支持 | 不支持 | 29 30#### 权限列表 31 32- 33 34#### 导入模块 35 36``` 37import bundle from '@ohos.bundle'; 38``` 39 40 41 42#### getApplicationInfo(bundleName: string, bundleFlags: number, userId: number) 43 44* 功能说明 45 46 根据给定的bundle名称获取ApplicationInfo 47 48* getApplicationInfo参数描述 49 50 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 51 | ----------- | -------- | ------ | ---- | ------------------------------------------------------- | 52 | bundleName | 只读 | string | 是 | 应用名 | 53 | bundleFlags | 只读 | number | 是 | 0:返回默认app信息<<br/>8:返回包含permissions的app信息 | 54 | userId | 只读 | number | 是 | 用户ID | 55 56* 返回值 57 58 Promise<ApplicationInfo>:返回值为Promise对象,Promise中包含应用信息。 59 60* 示例 61 62``` 63bundle.getApplicationInfo('com.example.myapplicationInstall', 8, 0).then((data) => { 64 console.info("name: for begin"); 65 console.info("name:" + data.name); 66 console.info("bundleName:" + data.bundleName); 67 console.info("description:" + data.description); 68 console.info("descriptionId:" + data.descriptionId); 69 console.info("iconPath:" + data.iconPath); 70 console.info("iconId:" + data.iconId); 71 console.info("label:" + data.label); 72 console.info("labelId:" + data.labelId); 73 console.info("deviceId:" + data.deviceId); 74 console.info("signatureKey:" + data.signatureKey); 75 console.info("process:" + data.process); 76 console.info("isSystemApp:" + data.isSystemApp); 77 console.info("isLauncherApp:" + data.isLauncherApp); 78 console.info("supportedModes:" + data.supportedModes); 79 80 console.info('getApplicationInfo permissions length [' + data.permissions.length + ']'); 81 for (var j = 0; j < data.permissions.length; j++) { 82 console.info("permissions[" + j + "]:" + data.permissions[j]); 83 } 84 console.info('getApplicationInfo moduleSourceDirs length [' + data.moduleSourceDirs.length + ']'); 85 for (var j = 0; j < data.moduleSourceDirs.length; j++) { 86 console.info("moduleSourceDirs[" + j + "]:" + data.moduleSourceDirs[j]); 87 } 88 console.info('getApplicationInfo moduleInfos length [' + data.moduleInfos.length + ']'); 89 for (var j = 0; j < data.moduleInfos.length; j++) { 90 console.info("moduleInfos[" + j + "]moduleName:" + data.moduleInfos[j].moduleName); 91 console.info("moduleInfos[" + j + "]moduleSourceDir:" + data.moduleInfos[j].moduleSourceDir); 92 } 93 console.info("entryDir:" + data.entryDir); 94 console.info("codePath:" + data.codePath); 95 console.info("dataDir:" + data.dataDir); 96 console.info("dataBaseDir:" + data.dataBaseDir); 97 console.info("cacheDir:" + data.cacheDir); 98}) 99``` 100 101 102 103#### getApplicationInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback<ApplicationInfo>) 104 105* 功能说明 106 107 根据给定的bundle名称获取ApplicationInfo 108 109* getApplicationInfo参数描述 110 111 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 112 | ----------- | -------- | ------------------------------ | ---- | ------------------------------------------------------- | 113 | bundleName | 只读 | string | 是 | 应用名 | 114 | bundleFlags | 只读 | number | 是 | 0:返回默认app信息<<br/>8:返回包含permissions的app信息 | 115 | userId | 只读 | number | 是 | 用户ID | 116 | callback | 只读 | AsyncCallback<ApplicationInfo> | 是 | 回调方法 | 117 118* 返回值 119 120 void 121 122* 示例 123 124``` 125bundle.getApplicationInfo('com.example.myapplicationInstall', 8, 0, OnReceiveEvent); 126 127function OnReceiveEvent(err, data) { 128 console.info("name: for begin"); 129 console.info("name:" + data.name); 130 console.info("bundleName:" + data.bundleName); 131 console.info("description:" + data.description); 132 console.info("descriptionId:" + data.descriptionId); 133 console.info("iconPath:" + data.iconPath); 134 console.info("iconId:" + data.iconId); 135 console.info("label:" + data.label); 136 console.info("labelId:" + data.labelId); 137 console.info("deviceId:" + data.deviceId); 138 console.info("signatureKey:" + data.signatureKey); 139 console.info("process:" + data.process); 140 console.info("isSystemApp:" + data.isSystemApp); 141 console.info("isLauncherApp:" + data.isLauncherApp); 142 console.info("supportedModes:" + data.supportedModes); 143 144 console.info('getApplicationInfo permissions length [' + data.permissions.length + ']'); 145 for (var j = 0; j < data.permissions.length; j++) { 146 console.info("permissions[" + j + "]:" + data.permissions[j]); 147 } 148 console.info('getApplicationInfo moduleSourceDirs length [' + data.moduleSourceDirs.length + ']'); 149 for (var j = 0; j < data.moduleSourceDirs.length; j++) { 150 console.info("moduleSourceDirs[" + j + "]:" + data.moduleSourceDirs[j]); 151 } 152 console.info('getApplicationInfo moduleInfos length [' + data.moduleInfos.length + ']'); 153 for (var j = 0; j < data.moduleInfos.length; j++) { 154 console.info("moduleInfos[" + j + "]moduleName:" + data.moduleInfos[j].moduleName); 155 console.info("moduleInfos[" + j + "]moduleSourceDir:" + data.moduleInfos[j].moduleSourceDir); 156 } 157 console.info("entryDir:" + data.entryDir); 158 console.info("codePath:" + data.codePath); 159 console.info("dataDir:" + data.dataDir); 160 console.info("dataBaseDir:" + data.dataBaseDir); 161 console.info("cacheDir:" + data.cacheDir); 162} 163``` 164 165 166 167#### getAllBundleInfo(bundleFlag: BundleFlag) 168 169* 功能说明 170 171 获取系统中所有可用的包信息 172 173* getAllBundleInfo参数描述 174 175 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 176 | ---------- | -------- | ---------- | ---- | ----------------------------------------------------------- | 177 | bundleFlag | 只读 | BundleFlag | 是 | 0:返回默认BundleInfo<br>1:返回包含abilityInfo的BundleInfo | 178 179* 返回值 180 181 Promise<Array<BundleInfo>>:返回值为Promise对象,Promise中包含包信息列表。 182 183* 示例 184 185``` 186bundle.getAllBundleInfo(0).then((data) => { 187 for (var i = 0; i < data.length; i++) { 188 console.info("index[" + i + "].name: for begin"); 189 console.info("index[" + i + "].name:" + data[i].name); 190 console.info("index[" + i + "].label:" + data[i].label); 191 console.info("index[" + i + "].description:" + data[i].description); 192 console.info("index[" + i + "].vendor:" + data[i].vendor); 193 console.info("index[" + i + "].versionCode:" + data[i].versionCode); 194 console.info("index[" + i + "].versionName:" + data[i].versionName); 195 console.info("index[" + i + "].jointUserId:" + data[i].jointUserId); 196 console.info("index[" + i + "].minSdkVersion:" + data[i].minSdkVersion); 197 console.info("index[" + i + "].maxSdkVersion:" + data[i].maxSdkVersion); 198 console.info("index[" + i + "].mainEntry:" + data[i].mainEntry); 199 console.info("index[" + i + "].cpuAbi:" + data[i].cpuAbi); 200 console.info("index[" + i + "].appId:" + data[i].appId); 201 console.info("index[" + i + "].compatibleVersion:" + data[i].compatibleVersion); 202 console.info("index[" + i + "].targetVersion:" + data[i].targetVersion); 203 console.info("index[" + i + "].releaseType:" + data[i].releaseType); 204 console.info("index[" + i + "].uid:" + data[i].uid); 205 console.info("index[" + i + "].gid:" + data[i].gid); 206 console.info("index[" + i + "].seInfo:" + data[i].seInfo); 207 console.info("index[" + i + "].entryModuleName:" + data[i].entryModuleName); 208 console.info("index[" + i + "].isKeepAlive:" + data[i].isKeepAlive); 209 console.info("index[" + i + "].isNativeApp:" + data[i].isNativeApp); 210 console.info("index[" + i + "].installTime:" + data[i].installTime); 211 console.info("index[" + i + "].updateTime:" + data[i].updateTime); 212 console.info("index[" + i + "].appInfo.name:" + data[i].applicationInfo.name); 213 console.info("index[" + i + "].appInfo.bundleName:" + data[i].applicationInfo.bundleName); 214 console.info('getAllBundleInfo reqPermissions length [' + data[i].reqPermissions.length + ']'); 215 for (var j = 0; j < data[i].reqPermissions.length; j++) { 216 console.info("index[" + i + "]reqPermissions[" + j + "]:" + data[i].reqPermissions[j]); 217 } 218 console.info('getAllBundleInfo defPermissions length [' + data[i].defPermissions.length + ']'); 219 for (var j = 0; j < data[i].defPermissions.length; j++) { 220 console.info("index[" + i + "]defPermissions[" + j + "]:" + data[i].defPermissions[j]); 221 } 222 223 console.info('getAllBundleInfo hapModuleNames length [' + data[i].hapModuleNames.length + ']'); 224 for (var j = 0; j < data[i].hapModuleNames.length; j++) { 225 console.info("index[" + i + "]hapModuleNames[" + j + "]:" + data[i].hapModuleNames[j]); 226 } 227 console.info('getAllBundleInfo moduleNames length [' + data[i].moduleNames.length + ']'); 228 for (var j = 0; j < data[i].moduleNames.length; j++) { 229 console.info("index[" + i + "]moduleNames[" + j + "]:" + data[i].moduleNames[j]); 230 } 231 console.info('getAllBundleInfo modulePublicDirs length [' + data[i].modulePublicDirs.length + ']'); 232 for (var j = 0; j < data[i].modulePublicDirs.length; j++) { 233 console.info("index[" + i + "]modulePublicDirs[" + j + "]:" + data[i].modulePublicDirs[j]); 234 } 235 console.info('getAllBundleInfo moduleDirs length [' + data[i].moduleDirs.length + ']'); 236 for (var j = 0; j < data[i].moduleDirs.length; j++) { 237 console.info("index[" + i + "]moduleDirs[" + j + "]:" + data[i].moduleDirs[j]); 238 } 239 console.info('getAllBundleInfo moduleResPaths length [' + data[i].moduleResPaths.length + ']'); 240 for (var j = 0; j < data[i].moduleResPaths.length; j++) { 241 console.info("index[" + i + "]moduleResPaths[" + j + "]:" + data[i].moduleResPaths[j]); 242 } 243 console.info('getAllBundleInfo abilityInfo length [' + data[i].abilityInfos.length + ']'); 244 for (var j = 0; j < data[i].abilityInfos.length; j++) { 245 console.info("index[" + i + "]abilityInfos[" + j + "]name:" + data[i].abilityInfos[j].name); 246 console.info("index[" + i + "]abilityInfos[" + j + "]package:" + data[i].abilityInfos[j].package); 247 } 248 } 249}) 250``` 251 252 253 254#### getAllBundleInfo(bundleFlag: BundleFlag, callback: AsyncCallback<Array<BundleInfo>>) 255 256* 功能说明 257 258 获取系统中所有可用的包信息 259 260* getAllBundleInfo参数描述 261 262 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 263 | ---------- | -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 264 | bundleFlag | 只读 | BundleFlag | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo | 265 | callback | 只读 | AsyncCallback<Array<BundleInfo>> | 是 | 回调方法 | 266 267* 返回值 268 269 void 270 271* 示例 272 273``` 274bundle.getAllBundleInfo(0, OnReceiveEvent); 275 276function OnReceiveEvent(err, data) { 277 console.info('xxx getAllBundleInfo data length [' + data.length + ']'); 278 for (var i = 0; i < data.length; i++) { 279 console.info("index[" + i + "].name: for begin"); 280 console.info("index[" + i + "].name:" + data[i].name); 281 console.info("index[" + i + "].label:" + data[i].label); 282 console.info("index[" + i + "].description:" + data[i].description); 283 console.info("index[" + i + "].vendor:" + data[i].vendor); 284 console.info("index[" + i + "].versionCode:" + data[i].versionCode); 285 console.info("index[" + i + "].versionName:" + data[i].versionName); 286 console.info("index[" + i + "].jointUserId:" + data[i].jointUserId); 287 console.info("index[" + i + "].minSdkVersion:" + data[i].minSdkVersion); 288 console.info("index[" + i + "].maxSdkVersion:" + data[i].maxSdkVersion); 289 console.info("index[" + i + "].mainEntry:" + data[i].mainEntry); 290 console.info("index[" + i + "].cpuAbi:" + data[i].cpuAbi); 291 console.info("index[" + i + "].appId:" + data[i].appId); 292 console.info("index[" + i + "].compatibleVersion:" + data[i].compatibleVersion); 293 console.info("index[" + i + "].targetVersion:" + data[i].targetVersion); 294 console.info("index[" + i + "].releaseType:" + data[i].releaseType); 295 console.info("index[" + i + "].uid:" + data[i].uid); 296 console.info("index[" + i + "].gid:" + data[i].gid); 297 console.info("index[" + i + "].seInfo:" + data[i].seInfo); 298 console.info("index[" + i + "].entryModuleName:" + data[i].entryModuleName); 299 console.info("index[" + i + "].isKeepAlive:" + data[i].isKeepAlive); 300 console.info("index[" + i + "].isNativeApp:" + data[i].isNativeApp); 301 console.info("index[" + i + "].installTime:" + data[i].installTime); 302 console.info("index[" + i + "].updateTime:" + data[i].updateTime); 303 console.info("index[" + i + "].appInfo.name:" + data[i].applicationInfo.name); 304 console.info("index[" + i + "].appInfo.bundleName:" + data[i].applicationInfo.bundleName); 305 console.info('getAllBundleInfo reqPermissions length [' + data[i].reqPermissions.length + ']'); 306 for (var j = 0; j < data[i].reqPermissions.length; j++) { 307 console.info("index[" + i + "]reqPermissions[" + j + "]:" + data[i].reqPermissions[j]); 308 } 309 console.info('getAllBundleInfo defPermissions length [' + data[i].defPermissions.length + ']'); 310 for (var j = 0; j < data[i].defPermissions.length; j++) { 311 console.info("index[" + i + "]defPermissions[" + j + "]:" + data[i].defPermissions[j]); 312 } 313 314 console.info('getAllBundleInfo hapModuleNames length [' + data[i].hapModuleNames.length + ']'); 315 for (var j = 0; j < data[i].hapModuleNames.length; j++) { 316 console.info("index[" + i + "]hapModuleNames[" + j + "]:" + data[i].hapModuleNames[j]); 317 } 318 console.info('getAllBundleInfo moduleNames length [' + data[i].moduleNames.length + ']'); 319 for (var j = 0; j < data[i].moduleNames.length; j++) { 320 console.info("index[" + i + "]moduleNames[" + j + "]:" + data[i].moduleNames[j]); 321 } 322 console.info('getAllBundleInfo modulePublicDirs length [' + data[i].modulePublicDirs.length + ']'); 323 for (var j = 0; j < data[i].modulePublicDirs.length; j++) { 324 console.info("index[" + i + "]modulePublicDirs[" + j + "]:" + data[i].modulePublicDirs[j]); 325 } 326 console.info('getAllBundleInfo moduleDirs length [' + data[i].moduleDirs.length + ']'); 327 for (var j = 0; j < data[i].moduleDirs.length; j++) { 328 console.info("index[" + i + "]moduleDirs[" + j + "]:" + data[i].moduleDirs[j]); 329 } 330 console.info('getAllBundleInfo moduleResPaths length [' + data[i].moduleResPaths.length + ']'); 331 for (var j = 0; j < data[i].moduleResPaths.length; j++) { 332 console.info("index[" + i + "]moduleResPaths[" + j + "]:" + data[i].moduleResPaths[j]); 333 } 334 console.info('getAllBundleInfo abilityInfo length [' + data[i].abilityInfos.length + ']'); 335 for (var j = 0; j < data[i].abilityInfos.length; j++) { 336 console.info("index[" + i + "]abilityInfos[" + j + "]name:" + data[i].abilityInfos[j].name); 337 console.info("index[" + i + "]abilityInfos[" + j + "]package:" + data[i].abilityInfos[j].package); 338 } 339 } 340} 341``` 342 343 344 345#### getBundleInfo(bundleName: string, bundleFlags: number) 346 347* 功能说明 348 349 根据bundle名称获取BundleInfo 350 351* getBundleInfo参数描述 352 353 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 354 | ----------- | -------- | ------ | ---- | ------------------------------------------------------------ | 355 | bundleName | 只读 | string | 是 | 包名 | 356 | bundleFlags | 只读 | number | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo | 357 358* 返回值 359 360 Promise<BundleInfo>:返回值为Promise对象,Promise中包含包信息。 361 362* 示例 363 364``` 365bundle.getBundleInfo('com.example.myapplicationInstall', 1).then((data) => { 366 console.info("name:" + data.name); 367 console.info("label:" + data.label); 368 console.info("description:" + data.description); 369 console.info("vendor:" + data.vendor); 370 console.info("versionCode:" + data.versionCode); 371 console.info("versionName:" + data.versionName); 372 console.info("jointUserId:" + data.jointUserId); 373 console.info("minSdkVersion:" + data.minSdkVersion); 374 console.info("maxSdkVersion:" + data.maxSdkVersion); 375 console.info("mainEntry:" + data.mainEntry); 376 console.info("cpuAbi:" + data.cpuAbi); 377 console.info("appId:" + data.appId); 378 console.info("compatibleVersion:" + data.compatibleVersion); 379 console.info("targetVersion:" + data.targetVersion); 380 console.info("releaseType:" + data.releaseType); 381 console.info("uid:" + data.uid); 382 console.info("gid:" + data.gid); 383 console.info("seInfo:" + data.seInfo); 384 console.info("entryModuleName:" + data.entryModuleName); 385 console.info("isKeepAlive:" + data.isKeepAlive); 386 console.info("isNativeApp:" + data.isNativeApp); 387 console.info("installTime:" + data.installTime); 388 console.info("updateTime:" + data.updateTime); 389 console.info("appInfo.name:" + data.applicationInfo.name); 390 console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); 391 console.info('getBundleInfo reqPermissions length [' + data.reqPermissions.length + ']'); 392 for (var j = 0; j < data.reqPermissions.length; j++) { 393 console.info("reqPermissions[" + j + "]:" + data.reqPermissions[j]); 394 } 395 console.info('getBundleInfo defPermissions length [' + data.defPermissions.length + ']'); 396 for (var j = 0; j < data.defPermissions.length; j++) { 397 console.info("defPermissions[" + j + "]:" + data.defPermissions[j]); 398 } 399 400 console.info('getBundleInfo hapModuleNames length [' + data.hapModuleNames.length + ']'); 401 for (var j = 0; j < data.hapModuleNames.length; j++) { 402 console.info("hapModuleNames[" + j + "]:" + data.hapModuleNames[j]); 403 } 404 console.info('getBundleInfo moduleNames length [' + data.moduleNames.length + ']'); 405 for (var j = 0; j < data.moduleNames.length; j++) { 406 console.info("moduleNames[" + j + "]:" + data.moduleNames[j]); 407 } 408 console.info('getBundleInfo modulePublicDirs length [' + data.modulePublicDirs.length + ']'); 409 for (var j = 0; j < data.modulePublicDirs.length; j++) { 410 console.info("modulePublicDirs[" + j + "]:" + data.modulePublicDirs[j]); 411 } 412 console.info('getBundleInfo moduleDirs length [' + data.moduleDirs.length + ']'); 413 for (var j = 0; j < data.moduleDirs.length; j++) { 414 console.info("moduleDirs[" + j + "]:" + data.moduleDirs[j]); 415 } 416 console.info('getBundleInfo moduleResPaths length [' + data.moduleResPaths.length + ']'); 417 for (var j = 0; j < data.moduleResPaths.length; j++) { 418 console.info("moduleResPaths[" + j + "]:" + data.moduleResPaths[j]); 419 } 420 console.info('getBundleInfo abilityInfo length [' + data.abilityInfos.length + ']'); 421 for (var j = 0; j < data.abilityInfos.length; j++) { 422 console.info("abilityInfos[" + j + "]name:" + data.abilityInfos[j].name); 423 console.info("abilityInfos[" + j + "]package:" + data.abilityInfos[j].package); 424 } 425}) 426``` 427 428 429 430#### getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback<BundleInfo>) 431 432* 功能说明 433 434 根据bundle名称获取BundleInfo 435 436* getBundleInfo参数描述 437 438 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 439 | ----------- | -------- | ------------------------- | ---- | ------------------------------------------------------------ | 440 | bundleName | 只读 | string | 是 | 包名 | 441 | bundleFlags | 只读 | number | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo | 442 | callback | 只读 | AsyncCallback<BundleInfo> | 是 | 回调方法 | 443 444* 返回值 445 446 void 447 448* 示例 449 450``` 451bundle.getBundleInfo('com.example.myapplicationInstall', 1, OnReceiveEvent); 452 453function OnReceiveEvent(err, data) { 454 console.info("name:" + data.name); 455 console.info("label:" + data.label); 456 console.info("description:" + data.description); 457 console.info("vendor:" + data.vendor); 458 console.info("versionCode:" + data.versionCode); 459 console.info("versionName:" + data.versionName); 460 console.info("jointUserId:" + data.jointUserId); 461 console.info("minSdkVersion:" + data.minSdkVersion); 462 console.info("maxSdkVersion:" + data.maxSdkVersion); 463 console.info("mainEntry:" + data.mainEntry); 464 console.info("cpuAbi:" + data.cpuAbi); 465 console.info("appId:" + data.appId); 466 console.info("compatibleVersion:" + data.compatibleVersion); 467 console.info("targetVersion:" + data.targetVersion); 468 console.info("releaseType:" + data.releaseType); 469 console.info("uid:" + data.uid); 470 console.info("gid:" + data.gid); 471 console.info("seInfo:" + data.seInfo); 472 console.info("entryModuleName:" + data.entryModuleName); 473 console.info("isKeepAlive:" + data.isKeepAlive); 474 console.info("isNativeApp:" + data.isNativeApp); 475 console.info("installTime:" + data.installTime); 476 console.info("updateTime:" + data.updateTime); 477 console.info("appInfo.name:" + data.applicationInfo.name); 478 console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); 479 console.info('getBundleInfo reqPermissions length [' + data.reqPermissions.length + ']'); 480 for (var j = 0; j < data.reqPermissions.length; j++) { 481 console.info("reqPermissions[" + j + "]:" + data.reqPermissions[j]); 482 } 483 console.info('getBundleInfo defPermissions length [' + data.defPermissions.length + ']'); 484 for (var j = 0; j < data.defPermissions.length; j++) { 485 console.info("defPermissions[" + j + "]:" + data.defPermissions[j]); 486 } 487 488 console.info('getBundleInfo hapModuleNames length [' + data.hapModuleNames.length + ']'); 489 for (var j = 0; j < data.hapModuleNames.length; j++) { 490 console.info("hapModuleNames[" + j + "]:" + data.hapModuleNames[j]); 491 } 492 console.info('getBundleInfo moduleNames length [' + data.moduleNames.length + ']'); 493 for (var j = 0; j < data.moduleNames.length; j++) { 494 console.info("moduleNames[" + j + "]:" + data.moduleNames[j]); 495 } 496 console.info('getBundleInfo modulePublicDirs length [' + data.modulePublicDirs.length + ']'); 497 for (var j = 0; j < data.modulePublicDirs.length; j++) { 498 console.info("modulePublicDirs[" + j + "]:" + data.modulePublicDirs[j]); 499 } 500 console.info('getBundleInfo moduleDirs length [' + data.moduleDirs.length + ']'); 501 for (var j = 0; j < data.moduleDirs.length; j++) { 502 console.info("moduleDirs[" + j + "]:" + data.moduleDirs[j]); 503 } 504 console.info('getBundleInfo moduleResPaths length [' + data.moduleResPaths.length + ']'); 505 for (var j = 0; j < data.moduleResPaths.length; j++) { 506 console.info("moduleResPaths[" + j + "]:" + data.moduleResPaths[j]); 507 } 508 console.info('getBundleInfo abilityInfo length [' + data.abilityInfos.length + ']'); 509 for (var j = 0; j < data.abilityInfos.length; j++) { 510 console.info("abilityInfos[" + j + "]name:" + data.abilityInfos[j].name); 511 console.info("abilityInfos[" + j + "]package:" + data.abilityInfos[j].package); 512 } 513} 514``` 515 516 517 518#### getAllApplicationInfo(bundleFlags: number, userId: number) 519 520* 功能说明 521 522 获取指定用户下所有已安装的应用信息 523 524* getAllApplicationInfo参数描述 525 526 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 527 | ----------- | -------- | ------ | ---- | ------------------------------------------------------- | 528 | bundleFlags | 只读 | number | 是 | 0:返回默认app信息<<br/>8:返回包含permissions的app信息 | 529 | userId | 只读 | number | 是 | 用户ID | 530 531* 返回值 532 533 Promise<Array<ApplicationInfo>>:返回值为Promise对象,Promise中包含应用信息列表。 534 535* 示例 536 537``` 538bundle.getAllApplicationInfo(8, 0).then((data) => { 539 console.info('xxx getAllApplicationInfo data length [' + data.length + ']'); 540 for (var i = 0; i < data.length; i++) { 541 console.info("index[" + i + "].name: for begin"); 542 console.info("index[" + i + "].name:" + data[i].name); 543 console.info("index[" + i + "].bundleName:" + data[i].bundleName); 544 console.info("index[" + i + "].description:" + data[i].description); 545 console.info("index[" + i + "].descriptionId:" + data[i].descriptionId); 546 console.info("index[" + i + "].iconPath:" + data[i].iconPath); 547 console.info("index[" + i + "].iconId:" + data[i].iconId); 548 console.info("index[" + i + "].label:" + data[i].label); 549 console.info("index[" + i + "].labelId:" + data[i].labelId); 550 console.info("index[" + i + "].deviceId:" + data[i].deviceId); 551 console.info("index[" + i + "].signatureKey:" + data[i].signatureKey); 552 console.info("index[" + i + "].process:" + data[i].process); 553 console.info("index[" + i + "].isSystemApp:" + data[i].isSystemApp); 554 console.info("index[" + i + "].isLauncherApp:" + data[i].isLauncherApp); 555 console.info("index[" + i + "].supportedModes:" + data[i].supportedModes); 556 557 console.info('getAllApplicationInfo Async permissions length [' + data[i].permissions.length + ']'); 558 for (var j = 0; j < data[i].permissions.length; j++) { 559 console.info("index[" + i + "]permissions[" + j + "]:" + data[i].permissions[j]); 560 } 561 console.info('getAllApplicationInfo Async moduleSourceDirs length [' + data[i].moduleSourceDirs.length + ']'); 562 for (var j = 0; j < data[i].moduleSourceDirs.length; j++) { 563 console.info("index[" + i + "]moduleSourceDirs[" + j + "]:" + data[i].moduleSourceDirs[j]); 564 } 565 console.info('getAllApplicationInfo Async moduleInfos length [' + data[i].moduleInfos.length + ']'); 566 for (var j = 0; j < data[i].moduleInfos.length; j++) { 567 console.info("index[" + i + "]moduleInfos[" + j + "]moduleName:" + data[i].moduleInfos[j].moduleName); 568 console.info("index[" + i + "]moduleInfos[" + j + "]moduleSourceDir:" + data[i].moduleInfos[j].moduleSourceDir); 569 } 570 console.info("index[" + i + "].entryDir:" + data[i].entryDir); 571 console.info("index[" + i + "].codePath:" + data[i].codePath); 572 console.info("index[" + i + "].dataDir:" + data[i].dataDir); 573 console.info("index[" + i + "].dataBaseDir:" + data[i].dataBaseDir); 574 console.info("index[" + i + "].cacheDir:" + data[i].cacheDir); 575 } 576}) 577``` 578 579 580 581#### getAllApplicationInfo(bundleFlags: number, userId: number, callback: AsyncCallback<Array<ApplicationInfo>>) 582 583* 功能说明 584 585 获取指定用户下所有已安装的应用信息 586 587* getAllApplicationInfo参数描述 588 589 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 590 | ----------- | -------- | ------------------------------------- | ---- | ------------------------------------------------------- | 591 | bundleFlags | 只读 | number | 是 | 0:返回默认app信息<<br/>8:返回包含permissions的app信息 | 592 | userId | 只读 | number | 是 | 用户ID | 593 | callback | 只读 | AsyncCallback<Array<ApplicationInfo>> | 是 | 回调方法 | 594 595* 返回值 596 597 void 598 599* 示例 600 601``` 602bundle.getAllApplicationInfo(8, 0, OnReceiveEvent); 603 604function OnReceiveEvent(err, data) { 605 console.info('xxx getAllApplicationInfo data length [' + data.length + ']'); 606 for (var i = 0; i < data.length; i++) { 607 console.info("index[" + i + "].name: for begin"); 608 console.info("index[" + i + "].name:" + data[i].name); 609 console.info("index[" + i + "].bundleName:" + data[i].bundleName); 610 console.info("index[" + i + "].description:" + data[i].description); 611 console.info("index[" + i + "].descriptionId:" + data[i].descriptionId); 612 console.info("index[" + i + "].iconPath:" + data[i].iconPath); 613 console.info("index[" + i + "].iconId:" + data[i].iconId); 614 console.info("index[" + i + "].label:" + data[i].label); 615 console.info("index[" + i + "].labelId:" + data[i].labelId); 616 console.info("index[" + i + "].deviceId:" + data[i].deviceId); 617 console.info("index[" + i + "].signatureKey:" + data[i].signatureKey); 618 console.info("index[" + i + "].process:" + data[i].process); 619 console.info("index[" + i + "].isSystemApp:" + data[i].isSystemApp); 620 console.info("index[" + i + "].isLauncherApp:" + data[i].isLauncherApp); 621 console.info("index[" + i + "].supportedModes:" + data[i].supportedModes); 622 623 console.info('getAllApplicationInfo Async permissions length [' + data[i].permissions.length + ']'); 624 for (var j = 0; j < data[i].permissions.length; j++) { 625 console.info("index[" + i + "]permissions[" + j + "]:" + data[i].permissions[j]); 626 } 627 console.info('getAllApplicationInfo Async moduleSourceDirs length [' + data[i].moduleSourceDirs.length + ']'); 628 for (var j = 0; j < data[i].moduleSourceDirs.length; j++) { 629 console.info("index[" + i + "]moduleSourceDirs[" + j + "]:" + data[i].moduleSourceDirs[j]); 630 } 631 console.info('getAllApplicationInfo Async moduleInfos length [' + data[i].moduleInfos.length + ']'); 632 for (var j = 0; j < data[i].moduleInfos.length; j++) { 633 console.info("index[" + i + "]moduleInfos[" + j + "]moduleName:" + data[i].moduleInfos[j].moduleName); 634 console.info("index[" + i + "]moduleInfos[" + j + "]moduleSourceDir:" + data[i].moduleInfos[j].moduleSourceDir); 635 } 636 console.info("index[" + i + "].entryDir:" + data[i].entryDir); 637 console.info("index[" + i + "].codePath:" + data[i].codePath); 638 console.info("index[" + i + "].dataDir:" + data[i].dataDir); 639 console.info("index[" + i + "].dataBaseDir:" + data[i].dataBaseDir); 640 console.info("index[" + i + "].cacheDir:" + data[i].cacheDir); 641 } 642} 643``` 644 645 646 647#### queryAbilityByWant(want: Want, bundleFlags: number, userId: number) 648 649* 功能说明 650 651 通过Want获取对应的Ability信息 652 653* queryAbilityInfo参数描述 654 655 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 656 | ----------- | -------- | ------ | ---- | ------------------------------------------------------------ | 657 | want | 只读 | Want | 是 | 指定Want信息 | 658 | bundleFlags | 只读 | number | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo | 659 | userId | 只读 | number | 是 | 用户ID | 660 661* Want类型说明 662 663 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 664 | ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | 665 | elementName | 只读 | ElementName | 是 | 表示运行指定Ability的ElementName。 | 666 | uri | 只读 | string | 否 | 表示Uri描述。 | 667 | flags | 只读 | int | 否 | Ability的flag,表示处理Want的方式。 | 668 | type | 只读 | string | 否 | Want中的type属性是指由Want的URI所指示的资源的MIME类型。 | 669 | action | 只读 | string | 否 | 表示动作,通常使用系统预置Action,应用也可以自定义Action。 | 670 | want_param | 只读 | {[key: string]: any} | 否 | want_param是一种支持自定义的数据结构,开发者可以通过want_param传递某些请求所需的额外信息。 | 671 | entities | 只读 | Array<string> | 否 | 表示类别,通常使用系统预置Entity,应用也可以自定义Entity。 | 672 673* ElementName类型说明 674 675 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 676 | ----------- | -------- | ------ | ---- | ------------------------------------------------------------ | 677 | deviceId | 只读 | string | 否 | 表示运行指定Ability的设备ID。 | 678 | bundleName | 只读 | string | 是 | 表示包描述。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 | 679 | abilityName | 只读 | string | 是 | 表示待启动的Ability名称。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 | 680 681* 返回值 682 683 Promise<Array<AbilityInfo>>:返回值为Promise对象,Promise中包含Ability信息。 684 685* 示例 686 687``` 688bundle.queryAbilityByWant({ 689 want: { 690 action: "action.system.home", 691 entities: ["entity.system.home"], 692 elementName: { 693 deviceId: "0", 694 bundleName: "com.example.myapplicationInstall", 695 abilityName: "com.example.myapplication.MainAbility", 696 }, 697 } 698}, 1, 0, 699}).then((data) => { 700 console.info("name:" + data.name); 701 console.info("label:" + data.label); 702 console.info("description:" + data.description); 703 console.info("iconPath:" + data.iconPath); 704 console.info("visible:" + data.visible); 705 console.info("kind:" + data.kind); 706 console.info("uri:" + data.uri); 707 console.info("process:" + data.process); 708 console.info("package:" + data.package); 709 console.info("bundleName:" + data.bundleName); 710 console.info("moduleName:" + data.moduleName); 711 console.info("applicationName:" + data.applicationName); 712 console.info("deviceId:" + data.deviceId); 713 console.info("codePath:" + data.codePath); 714 console.info("resourcePath:" + data.resourcePath); 715 console.info("libPath:" + data.libPath); 716 717 console.info('queryAbilityInfo permissions length [' + data.permissions.length + ']'); 718 for (var j = 0; j < data.permissions.length; j++) { 719 console.info("permissions[" + j + "]:" + data.permissions[j]); 720 } 721 console.info('queryAbilityInfo deviceTypes length [' + data.deviceTypes.length + ']'); 722 for (var j = 0; j < data.deviceTypes.length; j++) { 723 console.info("deviceTypes[" + j + "]:" + data.deviceTypes[j]); 724 } 725 console.info('queryAbilityInfo deviceCapabilities length [' + data.deviceCapabilities.length + ']'); 726 for (var j = 0; j < data.deviceCapabilities.length; j++) { 727 console.info("deviceCapabilities[" + j + "]:" + data.deviceCapabilities[j]); 728 } 729 console.info("appInfo.name:" + data.applicationInfo.name); 730 console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); 731 // ability type: 0:UNKNOWN, 1:PAGE, 2:SERVICE, 3:DATA 732 console.info("type:" + data.type); 733 // orientation: 0:UNSPECIFIED, 1:LANDSCAPE, 2:PORTRAIT, 3:FOLLOWRECENT, 734 console.info("orientation:" + data.orientation); 735 // launchMode: 0:SINGLETON, 1:SINGLETOP, 2:STANDARD 736 console.info("launchMode:" + data.launchMode); 737 738 // the enum of AbilityType 739 console.info("AbilityType:" + bundle.AbilityType.UNKNOWN); 740 console.info("AbilityType:" + bundle.AbilityType.PAGE); 741 console.info("AbilityType:" + bundle.AbilityType.SERVICE); 742 console.info("AbilityType:" + bundle.AbilityType.DATA); 743 if (data.type == bundle.AbilityType.PAGE) { 744 console.info("this AbilityType is PAGE"); 745 } 746 // the enum of DisplayOrientation 747 console.info("DisplayOrientation:" + bundle.DisplayOrientation.UNSPECIFIED); 748 console.info("DisplayOrientation:" + bundle.DisplayOrientation.LANDSCAPE); 749 console.info("DisplayOrientation:" + bundle.DisplayOrientation.PORTRAIT); 750 console.info("DisplayOrientation:" + bundle.DisplayOrientation.FOLLOWRECENT); 751 if (data.orientation == bundle.DisplayOrientation.UNSPECIFIED) { 752 console.info("this DisplayOrientation is UNSPECIFIED"); 753 } 754 // the enum of LaunchMode 755 console.info("LaunchMode:" + bundle.LaunchMode.SINGLETON); 756 console.info("LaunchMode:" + bundle.LaunchMode.SINGLETOP); 757 console.info("LaunchMode:" + bundle.LaunchMode.STANDARD); 758 if (data.launchMode == bundle.LaunchMode.STANDARD) { 759 console.info("this LaunchMode is STANDARD"); 760 } 761 762}) 763``` 764 765 766 767#### queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback<Array<AbilityInfo>>) 768 769* 功能说明 770 771 通过Want获取对应的Ability信息 772 773* queryAbilityInfo参数描述 774 775 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 776 | ----------- | -------- | --------------------------------- | ---- | ------------------------------------------------------------ | 777 | want | 只读 | Want | 是 | 指定Want信息 | 778 | bundleFlags | 只读 | number | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo | 779 | userId | 只读 | number | 是 | 用户ID | 780 | callback | 只读 | AsyncCallback<Array<AbilityInfo>> | 是 | 回调方法 | 781 782* Want类型说明 783 784 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 785 | ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | 786 | elementName | 只读 | ElementName | 是 | 表示运行指定Ability的ElementName。 | 787 | uri | 只读 | string | 否 | 表示Uri描述。 | 788 | flags | 只读 | int | 否 | Ability的flag,表示处理Want的方式。 | 789 | type | 只读 | string | 否 | Want中的type属性是指由Want的URI所指示的资源的MIME类型。 | 790 | action | 只读 | string | 否 | 表示动作,通常使用系统预置Action,应用也可以自定义Action。 | 791 | want_param | 只读 | {[key: string]: any} | 否 | want_param是一种支持自定义的数据结构,开发者可以通过want_param传递某些请求所需的额外信息。 | 792 | entities | 只读 | Array<string> | 否 | 表示类别,通常使用系统预置Entity,应用也可以自定义Entity。 | 793 794* ElementName类型说明 795 796 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 797 | ----------- | -------- | ------ | ---- | ------------------------------------------------------------ | 798 | deviceId | 只读 | string | 否 | 表示运行指定Ability的设备ID。 | 799 | bundleName | 只读 | string | 是 | 表示包描述。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 | 800 | abilityName | 只读 | string | 是 | 表示待启动的Ability名称。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 | 801 802* 返回值 803 804 void 805 806* 示例 807 808``` 809bundle.queryAbilityByWant( 810 { 811 want: { 812 action: "action.system.home", 813 entities: ["entity.system.home"], 814 elementName: { 815 deviceId: "0", 816 bundleName: "com.example.myapplicationInstall", 817 abilityName: "com.example.myapplication.MainAbility", 818 }, 819 } 820 }, 1, 0, 821 }, OnReceiveEvent); 822 823function OnReceiveEvent(err, data) { 824 console.info("name:" + data.name); 825 console.info("label:" + data.label); 826 console.info("description:" + data.description); 827 console.info("iconPath:" + data.iconPath); 828 console.info("visible:" + data.visible); 829 console.info("kind:" + data.kind); 830 console.info("uri:" + data.uri); 831 console.info("process:" + data.process); 832 console.info("package:" + data.package); 833 console.info("bundleName:" + data.bundleName); 834 console.info("moduleName:" + data.moduleName); 835 console.info("applicationName:" + data.applicationName); 836 console.info("deviceId:" + data.deviceId); 837 console.info("codePath:" + data.codePath); 838 console.info("resourcePath:" + data.resourcePath); 839 console.info("libPath:" + data.libPath); 840 841 console.info('queryAbilityInfo permissions length [' + data.permissions.length + ']'); 842 for (var j = 0; j < data.permissions.length; j++) { 843 console.info("permissions[" + j + "]:" + data.permissions[j]); 844 } 845 console.info('queryAbilityInfo deviceTypes length [' + data.deviceTypes.length + ']'); 846 for (var j = 0; j < data.deviceTypes.length; j++) { 847 console.info("deviceTypes[" + j + "]:" + data.deviceTypes[j]); 848 } 849 console.info('queryAbilityInfo deviceCapabilities length [' + data.deviceCapabilities.length + ']'); 850 for (var j = 0; j < data.deviceCapabilities.length; j++) { 851 console.info("deviceCapabilities[" + j + "]:" + data.deviceCapabilities[j]); 852 } 853 console.info("appInfo.name:" + data.applicationInfo.name); 854 console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); 855 // ability type: 0:UNKNOWN, 1:PAGE, 2:SERVICE, 3:DATA 856 console.info("type:" + data.type); 857 // orientation: 0:UNSPECIFIED, 1:LANDSCAPE, 2:PORTRAIT, 3:FOLLOWRECENT, 858 console.info("orientation:" + data.orientation); 859 // launchMode: 0:SINGLETON, 1:SINGLETOP, 2:STANDARD 860 console.info("launchMode:" + data.launchMode); 861 862 // the enum of AbilityType 863 console.info("AbilityType:" + bundle.AbilityType.UNKNOWN); 864 console.info("AbilityType:" + bundle.AbilityType.PAGE); 865 console.info("AbilityType:" + bundle.AbilityType.SERVICE); 866 console.info("AbilityType:" + bundle.AbilityType.DATA); 867 if (data.type == bundle.AbilityType.PAGE) { 868 console.info("this AbilityType is PAGE"); 869 } 870 // the enum of DisplayOrientation 871 console.info("DisplayOrientation:" + bundle.DisplayOrientation.UNSPECIFIED); 872 console.info("DisplayOrientation:" + bundle.DisplayOrientation.LANDSCAPE); 873 console.info("DisplayOrientation:" + bundle.DisplayOrientation.PORTRAIT); 874 console.info("DisplayOrientation:" + bundle.DisplayOrientation.FOLLOWRECENT); 875 if (data.orientation == bundle.DisplayOrientation.UNSPECIFIED) { 876 console.info("this DisplayOrientation is UNSPECIFIED"); 877 } 878 // the enum of LaunchMode 879 console.info("LaunchMode:" + bundle.LaunchMode.SINGLETON); 880 console.info("LaunchMode:" + bundle.LaunchMode.SINGLETOP); 881 console.info("LaunchMode:" + bundle.LaunchMode.STANDARD); 882 if (data.launchMode == bundle.LaunchMode.STANDARD) { 883 console.info("this LaunchMode is STANDARD"); 884 } 885} 886``` 887 888 889 890#### getPermissionDef(permissionName: string) 891 892* 功能说明 893 894 获取指定权限的详细信息 895 896* getPermissionDef参数描述 897 898 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 899 | -------------- | -------- | ------ | ---- | ------ | 900 | permissionName | 只读 | string | 是 | 权限名 | 901 902* 返回值 903 904 Promise<BundleInfo>:返回值为bundle信息。 905 906* 示例 907 908``` 909bundle.getPermissionDef('com.permission.CAMERA').then((data) => { 910 console.info("permissionName:" + data.permissionName); 911 console.info("bundleName:" + data.bundleName); 912 console.info("grantMode:" + data.grantMode); 913 console.info("availableScope:" + data.availableScope); 914 console.info("label:" + data.label); 915 console.info("labelId:" + data.labelId); 916}) 917``` 918 919 920 921#### getPermissionDef(permissionName: string, callback: AsyncCallback<PermissionDef>) 922 923* 功能说明 924 925 获取指定权限的详细信息 926 927* getPermissionDef参数描述 928 929 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 930 | -------------- | -------- | ---------------------------- | ---- | -------- | 931 | permissionName | 只读 | string | 是 | 权限名 | 932 | callback | 只读 | AsyncCallback<PermissionDef> | 是 | 回调方法 | 933 934* 返回值 935 936 void 937 938* 示例 939 940``` 941bundle.getBundleInstaller().then((data) => { 942 data.getPermissionDef('com.permission.CAMERA', OnReceiveEvent); 943 944 function OnReceiveEvent(err, data) { 945 console.info("permissionName:" + data.permissionName); 946 console.info("bundleName:" + data.bundleName); 947 console.info("grantMode:" + data.grantMode); 948 console.info("availableScope:" + data.availableScope); 949 console.info("label:" + data.label); 950 console.info("labelId:" + data.labelId); 951 } 952}) 953``` 954 955 956 957#### getBundleArchiveInfo(hapFilePath: string, bundleFlags: number) 958 959* 功能说明 960 961 获取HAP包含的应用包信息 962 963* getBundleArchiveInfo参数描述 964 965 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 966 | ----------- | -------- | ------ | ---- | ------------------------------------------------------------ | 967 | hapFilePath | 只读 | string | 是 | hap包文件路径 | 968 | bundleFlags | 只读 | number | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo | 969 970* 返回值 971 972 Promise<BundleInfo>:返回值为bundle信息。 973 974* 示例 975 976``` 977bundle.getBundleArchiveInfo('/data/test.hap', 1).then((data) => { 978 console.info("name:" + data.name); 979 console.info("label:" + data.label); 980 console.info("description:" + data.description); 981 console.info("vendor:" + data.vendor); 982 console.info("versionCode:" + data.versionCode); 983 console.info("versionName:" + data.versionName); 984 console.info("jointUserId:" + data.jointUserId); 985 console.info("minSdkVersion:" + data.minSdkVersion); 986 console.info("maxSdkVersion:" + data.maxSdkVersion); 987 console.info("mainEntry:" + data.mainEntry); 988 console.info("cpuAbi:" + data.cpuAbi); 989 console.info("appId:" + data.appId); 990 console.info("compatibleVersion:" + data.compatibleVersion); 991 console.info("targetVersion:" + data.targetVersion); 992 console.info("releaseType:" + data.releaseType); 993 console.info("uid:" + data.uid); 994 console.info("gid:" + data.gid); 995 console.info("seInfo:" + data.seInfo); 996 console.info("entryModuleName:" + data.entryModuleName); 997 console.info("isKeepAlive:" + data.isKeepAlive); 998 console.info("isNativeApp:" + data.isNativeApp); 999 console.info("installTime:" + data.installTime); 1000 console.info("updateTime:" + data.updateTime); 1001 console.info("appInfo.name:" + data.applicationInfo.name); 1002 console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); 1003 console.info('getBundleArchiveInfo reqPermissions length [' + data.reqPermissions.length + ']'); 1004 for (var j = 0; j < data.reqPermissions.length; j++) { 1005 console.info("reqPermissions[" + j + "]:" + data.reqPermissions[j]); 1006 } 1007 console.info('getBundleArchiveInfo defPermissions length [' + data.defPermissions.length + ']'); 1008 for (var j = 0; j < data.defPermissions.length; j++) { 1009 console.info("defPermissions[" + j + "]:" + data.defPermissions[j]); 1010 } 1011 console.info('getBundleArchiveInfo hapModuleNames length [' + data.hapModuleNames.length + ']'); 1012 for (var j = 0; j < data.hapModuleNames.length; j++) { 1013 console.info("hapModuleNames[" + j + "]:" + data.hapModuleNames[j]); 1014 } 1015 console.info('getBundleArchiveInfo moduleNames length [' + data.moduleNames.length + ']'); 1016 for (var j = 0; j < data.moduleNames.length; j++) { 1017 console.info("moduleNames[" + j + "]:" + data.moduleNames[j]); 1018 } 1019 console.info('getBundleArchiveInfo modulePublicDirs length [' + data.modulePublicDirs.length + ']'); 1020 for (var j = 0; j < data.modulePublicDirs.length; j++) { 1021 console.info("modulePublicDirs[" + j + "]:" + data.modulePublicDirs[j]); 1022 } 1023 console.info('getBundleArchiveInfo moduleDirs length [' + data.moduleDirs.length + ']'); 1024 for (var j = 0; j < data.moduleDirs.length; j++) { 1025 console.info("moduleDirs[" + j + "]:" + data.moduleDirs[j]); 1026 } 1027 console.info('getBundleArchiveInfo moduleResPaths length [' + data.moduleResPaths.length + ']'); 1028 for (var j = 0; j < data.moduleResPaths.length; j++) { 1029 console.info("moduleResPaths[" + j + "]:" + data.moduleResPaths[j]); 1030 } 1031 console.info('getBundleArchiveInfo abilityInfo length [' + data.abilityInfos.length + ']'); 1032 for (var j = 0; j < data.abilityInfos.length; j++) { 1033 console.info("abilityInfos[" + j + "]name:" + data.abilityInfos[j].name); 1034 console.info("abilityInfos[" + j + "]package:" + data.abilityInfos[j].package); 1035 } 1036}) 1037``` 1038 1039 1040 1041#### getBundleArchiveInfo(hapFilePath: string, bundleFlags: number, callback: AsyncCallback<BundleInfo>) 1042 1043* 功能说明 1044 1045 获取HAP包含的应用包信息 1046 1047* getBundleArchiveInfo参数描述 1048 1049 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 1050 | ----------- | -------- | ------------------------- | ---- | ------------------------------------------------------------ | 1051 | hapFilePath | 只读 | string | 是 | hap包文件路径 | 1052 | bundleFlags | 只读 | number | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo | 1053 | callback | 只读 | AsyncCallback<BundleInfo> | 是 | 回调方法 | 1054 1055* 返回值 1056 1057 void 1058 1059* 示例 1060 1061``` 1062bundle.getBundleArchiveInfo('/data/test.hap', 1, OnReceiveEvent); 1063 1064function OnReceiveEvent(err, data) { 1065 console.info("name:" + data.name); 1066 console.info("label:" + data.label); 1067 console.info("description:" + data.description); 1068 console.info("vendor:" + data.vendor); 1069 console.info("versionCode:" + data.versionCode); 1070 console.info("versionName:" + data.versionName); 1071 console.info("jointUserId:" + data.jointUserId); 1072 console.info("minSdkVersion:" + data.minSdkVersion); 1073 console.info("maxSdkVersion:" + data.maxSdkVersion); 1074 console.info("mainEntry:" + data.mainEntry); 1075 console.info("cpuAbi:" + data.cpuAbi); 1076 console.info("appId:" + data.appId); 1077 console.info("compatibleVersion:" + data.compatibleVersion); 1078 console.info("targetVersion:" + data.targetVersion); 1079 console.info("releaseType:" + data.releaseType); 1080 console.info("uid:" + data.uid); 1081 console.info("gid:" + data.gid); 1082 console.info("seInfo:" + data.seInfo); 1083 console.info("entryModuleName:" + data.entryModuleName); 1084 console.info("isKeepAlive:" + data.isKeepAlive); 1085 console.info("isNativeApp:" + data.isNativeApp); 1086 console.info("installTime:" + data.installTime); 1087 console.info("updateTime:" + data.updateTime); 1088 console.info("appInfo.name:" + data.applicationInfo.name); 1089 console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); 1090 console.info('getBundleArchiveInfo reqPermissions length [' + data.reqPermissions.length + ']'); 1091 for (var j = 0; j < data.reqPermissions.length; j++) { 1092 console.info("reqPermissions[" + j + "]:" + data.reqPermissions[j]); 1093 } 1094 console.info('getBundleArchiveInfo defPermissions length [' + data.defPermissions.length + ']'); 1095 for (var j = 0; j < data.defPermissions.length; j++) { 1096 console.info("defPermissions[" + j + "]:" + data.defPermissions[j]); 1097 } 1098 console.info('getBundleArchiveInfo hapModuleNames length [' + data.hapModuleNames.length + ']'); 1099 for (var j = 0; j < data.hapModuleNames.length; j++) { 1100 console.info("hapModuleNames[" + j + "]:" + data.hapModuleNames[j]); 1101 } 1102 console.info('getBundleArchiveInfo moduleNames length [' + data.moduleNames.length + ']'); 1103 for (var j = 0; j < data.moduleNames.length; j++) { 1104 console.info("moduleNames[" + j + "]:" + data.moduleNames[j]); 1105 } 1106 console.info('getBundleArchiveInfo modulePublicDirs length [' + data.modulePublicDirs.length + ']'); 1107 for (var j = 0; j < data.modulePublicDirs.length; j++) { 1108 console.info("modulePublicDirs[" + j + "]:" + data.modulePublicDirs[j]); 1109 } 1110 console.info('getBundleArchiveInfo moduleDirs length [' + data.moduleDirs.length + ']'); 1111 for (var j = 0; j < data.moduleDirs.length; j++) { 1112 console.info("moduleDirs[" + j + "]:" + data.moduleDirs[j]); 1113 } 1114 console.info('getBundleArchiveInfo moduleResPaths length [' + data.moduleResPaths.length + ']'); 1115 for (var j = 0; j < data.moduleResPaths.length; j++) { 1116 console.info("moduleResPaths[" + j + "]:" + data.moduleResPaths[j]); 1117 } 1118 console.info('getBundleArchiveInfo abilityInfo length [' + data.abilityInfos.length + ']'); 1119 for (var j = 0; j < data.abilityInfos.length; j++) { 1120 console.info("abilityInfos[" + j + "]name:" + data.abilityInfos[j].name); 1121 console.info("abilityInfos[" + j + "]package:" + data.abilityInfos[j].package); 1122 } 1123} 1124``` 1125 1126 1127 1128#### install(bundleFilePaths: Array<string>, param: InstallParam, callback: AsyncCallback<InstallStatus>) 1129 1130* 功能说明 1131 1132 安装hap包 1133 1134* install参数描述 1135 1136 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 1137 | --------------- | -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 1138 | bundleFilePaths | 只读 | Array<string> | 是 | 安装用包路径 | 1139 | param | 只读 | InstallParam | 是 | userId:用户ID<br/>installFlag:安装标识。<br/> NORMAL:安装/卸载<br/> REPLACE_EXISTING:更新<br/>isKeepData:卸载时是否保留运行时数据 | 1140 | callback | 只读 | AsyncCallback<InstallStatus> | 是 | 回调方法 | 1141 1142* 返回值 1143 1144 void 1145 1146* InstallStatus类型说明 1147 1148 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 1149 | ------------- | -------- | ---------------- | ---- | ------------------------------------------------------------ | 1150 | status | 只读 | InstallErrorCode | 是 | 安装结果code<br/>SUCCESS = 0<br/>STATUS_INSTALL_FAILURE = 1<br/>STATUS_INSTALL_FAILURE_ABORTED = 2,<br/>STATUS_INSTALL_FAILURE_INVALID = 3<br/>STATUS_INSTALL_FAILURE_CONFLICT = 4<br/>STATUS_INSTALL_FAILURE_STORAGE = 5<br/>STATUS_INSTALL_FAILURE_INCOMPATIBLE = 6<br/>STATUS_INSTALL_FAILURE_DOWNLOAD_TIMEOUT = 0x0B<br/>STATUS_INSTALL_FAILURE_DOWNLOAD_FAILED = 0x0C<br/>STATUS_ABILITY_NOT_FOUND = 0x40<br/>STATUS_BMS_SERVICE_ERROR = 0x41 | 1151 | statusMessage | 只读 | string | 是 | 安装结果Message | 1152 1153* 示例 1154 1155``` 1156bundle.getBundleInstaller().then((data) => { 1157 data.install(['/data/test.hap'], { 1158 param: { 1159 userId: 0, 1160 isKeepData: false 1161 } 1162 }, OnReceiveinstallEvent); 1163 1164 function OnReceiveinstallEvent(err, data) { 1165 console.info("name: for begin"); 1166 console.info("install result code:" + data.status); 1167 console.info("install result msg:" + data.statusMessage); 1168 } 1169}) 1170``` 1171 1172 1173 1174#### uninstall(bundleName: string, param: InstallParam, callback: AsyncCallback<InstallStatus>) 1175 1176* 功能说明 1177 1178 卸载hap包 1179 1180* uninstall参数描述 1181 1182 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 1183 | ---------- | -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 1184 | bundleName | 只读 | string | 是 | 卸载用包名 | 1185 | param | 只读 | InstallParam | 是 | userId:用户ID<br/>installFlag:安装标识。<br/> NORMAL:安装/卸载<br/> REPLACE_EXISTING:更新<br/>isKeepData:卸载时是否保留运行时数据 | 1186 | callback | 只读 | AsyncCallback<InstallStatus> | 是 | 回调方法 | 1187 1188* 返回值 1189 1190 void 1191 1192* InstallStatus类型说明 1193 1194 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 1195 | ------------- | -------- | ---------------- | ---- | ------------------------------------------------------------ | 1196 | status | 只读 | InstallErrorCode | 是 | 卸载结果code<br/>SUCCESS = 0<br/>STATUS_UNINSTALL_FAILURE = 7<br/>STATUS_UNINSTALL_FAILURE_BLOCKED = 8<br/>STATUS_UNINSTALL_FAILURE_ABORTED = 9,<br/>STATUS_UNINSTALL_FAILURE_CONFLICT = 10<br/>STATUS_ABILITY_NOT_FOUND = 0x40<br/>STATUS_BMS_SERVICE_ERROR = 0x41 | 1197 | statusMessage | 只读 | string | 是 | 卸载结果Message | 1198 1199* 示例 1200 1201``` 1202bundle.getBundleInstaller().then((data) => { 1203 data.uninstall('com.example.myapplication', { 1204 param: { 1205 userId: 0, 1206 isKeepData: false 1207 } 1208 }, OnReceiveinstallEvent); 1209 1210 function OnReceiveinstallEvent(err, data) { 1211 console.info("name: for begin"); 1212 console.info("uninstall result code:" + data.status); 1213 console.info("uninstall result msg:" + data.statusMessage); 1214 } 1215}) 1216``` 1217 1218 1219 1220#### getAllShortcutInfo(bundleName: string) 1221 1222* 功能说明 1223 1224 获取指定bundle名的shortcut信息 1225 1226* getAllShortcutInfo参数描述 1227 1228 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 1229 | ---------- | -------- | ------ | ---- | -------- | 1230 | bundleName | 只读 | string | 是 | bundle名 | 1231 1232* 返回值 1233 1234 Promise<ShortcutInfo>:返回值为bundle信息。 1235 1236* 示例 1237 1238``` 1239bundle.getAllShortcutInfo('com.example.third1').then((data) => { 1240 ... 1241}); 1242``` 1243 1244 1245 1246#### getAllShortcutInfo(bundleName: string, callback: AsyncCallback<Array<ShortcutInfo>>) 1247 1248* 功能说明 1249 1250 获取指定bundle名的shortcut信息 1251 1252* getAllShortcutInfo参数描述 1253 1254 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 1255 | ---------- | -------- | --------------------------- | ---- | -------- | 1256 | bundleName | 只读 | string | 是 | bundle名 | 1257 | callback | 只读 | AsyncCallback<ShortcutInfo> | 是 | 回调方法 | 1258 1259* 返回值 1260 1261 void 1262 1263* 示例 1264 1265``` 1266bundle.getAllShortcutInfo('com.example.third1', OnReceiveEvent); 1267 1268function OnReceiveEvent(err, data) { 1269 ... 1270} 1271``` 1272 1273 1274 1275#### checkPermission(bundleName: string, permission: string) 1276 1277* 功能说明 1278 1279 获取指定最大记录数的Usage信息 1280 1281* checkPermission参数描述 1282 1283 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 1284 | ---------- | -------- | ------ | ---- | -------- | 1285 | bundleName | 只读 | string | 是 | bundle名 | 1286 | permission | 只读 | string | 是 | 权限名 | 1287 1288* 返回值 1289 1290 Promise<GrantStatus>:返回值为bundle信息。 1291 1292* 示例 1293 1294``` 1295bundle.getModuleUsageRecords('com.example.actsbmscheckpermissiontest', 'com.permission.CAMERA').then((data) => { 1296 ... 1297}); 1298``` 1299 1300 1301 1302#### checkPermission(bundleName: string, permission: string, callback: AsyncCallback<GrantStatus>) 1303 1304* 功能说明 1305 1306 获取指定最大记录数的Usage信息 1307 1308* checkPermission参数描述 1309 1310 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 1311 | ---------- | -------- | -------------------------- | ---- | -------- | 1312 | bundleName | 只读 | string | 是 | bundle名 | 1313 | permission | 只读 | string | 是 | 权限名 | 1314 | callback | 只读 | AsyncCallback<GrantStatus> | 是 | 回调方法 | 1315 1316* 返回值 1317 1318 void 1319 1320* 示例 1321 1322``` 1323bundle.checkPermission('com.example.actsbmscheckpermissiontest', 'com.permission.CAMERA', OnReceiveEvent); 1324 1325function OnReceiveEvent(err, data) { 1326 ... 1327} 1328``` 1329