1# @ohos.bundle.appControl (appControl) 2 3The **appControl** module provides APIs for setting, obtaining, and deleting the disposed status of an application. An application in the disposed status is forbidden to run. When a user clicks the application icon on the home screen, the corresponding page is displayed based on the disposal intent. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13``` ts 14import appControl from '@ohos.bundle.appControl' 15``` 16 17## appControl.setDisposedStatus 18 19setDisposedStatus(appId: string, disposedWant: Want): Promise\<void> 20 21Sets the disposed status for an application. This API uses a promise to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 22 23**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 24 25**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 26 27**System API**: This is a system API. 28 29**Parameters** 30 31| Name | Type | Mandatory | Description | 32| ----------- | ------ | ---- | --------------------------------------- | 33| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 34| disposedWant | Want | Yes| Disposal intent of the application.| 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](../errorcodes/errorcode-bundle.md). 45 46| ID| Error Message | 47| ------ | -------------------------------------- | 48| 17700005 | The specified app ID is empty string. | 49 50**Example** 51 52```ts 53import { BusinessError } from '@ohos.base'; 54import Want from '@ohos.app.ability.Want'; 55import appControl from '@ohos.bundle.appControl'; 56 57let appId = "com.example.myapplication_xxxxx"; 58let want:Want = {bundleName: 'com.example.myapplication'}; 59 60try { 61 appControl.setDisposedStatus(appId, want) 62 .then(() => { 63 console.info('setDisposedStatus success'); 64 }).catch((error: BusinessError) => { 65 let message = (error as BusinessError).message; 66 console.error('setDisposedStatus failed ' + message); 67 }); 68} catch (error) { 69 let message = (error as BusinessError).message; 70 console.error('setDisposedStatus failed ' + message); 71} 72``` 73 74## appControl.setDisposedStatus 75 76setDisposedStatus(appId: string, disposedWant: Want, callback: AsyncCallback\<void>): void; 77 78Sets the disposed status for an application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 79 80**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 81 82**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 83 84**System API**: This is a system API. 85 86**Parameters** 87 88| Name | Type | Mandatory | Description | 89| ----------- | ------------------------------- | ---- | --------------------------------------- | 90| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 91| disposedWant | Want | Yes| Disposal intent of the application.| 92| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.| 93 94**Error codes** 95 96For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 97 98| ID| Error Message | 99| ------ | -------------------------------------- | 100| 17700005 | The specified app ID is empty string. | 101 102**Example** 103 104```ts 105import appControl from '@ohos.bundle.appControl'; 106import { BusinessError } from '@ohos.base'; 107import Want from '@ohos.app.ability.Want'; 108 109let appId = "com.example.myapplication_xxxxx"; 110let want: Want = {bundleName: 'com.example.myapplication'}; 111 112try { 113 appControl.setDisposedStatus(appId, want, (error: BusinessError, data) => { 114 if (error) { 115 let message = (error as BusinessError).message; 116 console.error('setDisposedStatus failed ' + message); 117 return; 118 } 119 console.info('setDisposedStatus success'); 120 }); 121} catch (error) { 122 let message = (error as BusinessError).message; 123 console.error('setDisposedStatus failed ' + message); 124} 125``` 126 127## appControl.setDisposedStatusSync<sup>10+</sup> 128 129setDisposedStatusSync(appId: string, disposedWant: Want): void; 130 131Sets the disposed status for an application. This API is a synchronous API. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 132 133**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 134 135**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 136 137**System API**: This is a system API. 138 139**Parameters** 140 141| Name | Type | Mandatory | Description | 142| ----------- | ------------------------------- | ---- | --------------------------------------- | 143| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 144| disposedWant | Want | Yes| Disposal intent of the application.| 145 146**Error codes** 147 148For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 149 150| ID| Error Message | 151| ------ | -------------------------------------- | 152| 17700005 | The specified app ID is empty string. | 153 154**Example** 155 156```ts 157import appControl from '@ohos.bundle.appControl'; 158import { BusinessError } from '@ohos.base'; 159import Want from '@ohos.app.ability.Want'; 160 161let appId: string = "com.example.myapplication_xxxxx"; 162let want: Want = {bundleName: 'com.example.myapplication'}; 163 164try { 165 appControl.setDisposedStatusSync(appId, want); 166} catch (error) { 167 let message = (error as BusinessError).message; 168 console.error('setDisposedStatusSync failed ' + message); 169} 170``` 171 172## appControl.getDisposedStatus 173 174getDisposedStatus(appId: string): Promise\<Want>; 175 176Obtains the disposed status of an application. This API uses a promise to return the result. If the operation is successful, the disposed status of the application is returned. If the operation fails, an error message is returned. 177 178**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 179 180**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 181 182**System API**: This is a system API. 183 184**Parameters** 185 186| Name | Type | Mandatory | Description | 187| ----------- | ------ | ---- | --------------------------------------- | 188| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 189 190**Return value** 191 192| Type | Description | 193| ------------------------- | ------------------ | 194| Promise\<Want> | Promise used to return the disposed status.| 195 196**Error codes** 197 198For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 199 200| ID| Error Message | 201| ------ | -------------------------------------- | 202| 17700005 | The specified app ID is empty string. | 203 204**Example** 205 206```ts 207import appControl from '@ohos.bundle.appControl'; 208import { BusinessError } from '@ohos.base'; 209 210let appId = "com.example.myapplication_xxxxx"; 211 212try { 213 appControl.getDisposedStatus(appId) 214 .then((data) => { 215 console.info('getDisposedStatus success. DisposedStatus: ' + JSON.stringify(data)); 216 }).catch((error: BusinessError) => { 217 let message = (error as BusinessError).message; 218 console.error('getDisposedStatus failed ' + message); 219 }); 220} catch (error) { 221 let message = (error as BusinessError).message; 222 console.error('getDisposedStatus failed ' + message); 223} 224``` 225 226## appControl.getDisposedStatus 227 228getDisposedStatus(appId: string, callback: AsyncCallback\<Want>): void; 229 230Obtains the disposed status of an application. This API uses an asynchronous callback to return the result. If the operation is successful, the disposed status of the application is returned. If the operation fails, an error message is returned. 231 232**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 233 234**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 235 236**System API**: This is a system API. 237 238**Parameters** 239 240| Name | Type | Mandatory | Description | 241| ----------- | ------ | ---- | --------------------------------------- | 242| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 243| callback | AsyncCallback\<Want> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the disposed status obtained; otherwise, **err** is an error object. | 244 245**Error codes** 246 247For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 248 249| ID| Error Message | 250| ------ | -------------------------------------- | 251| 17700005 | The specified app ID is empty string. | 252 253**Example** 254 255```ts 256import appControl from '@ohos.bundle.appControl'; 257import { BusinessError } from '@ohos.base'; 258 259let appId = "com.example.myapplication_xxxxx"; 260 261try { 262 appControl.getDisposedStatus(appId, (error, data) => { 263 if (error) { 264 let message = (error as BusinessError).message; 265 console.error('getDisposedStatus failed ' + message); 266 return; 267 } 268 console.info('getDisposedStatus success. DisposedStatus: ' + JSON.stringify(data)); 269 }); 270} catch (error) { 271 let message = (error as BusinessError).message; 272 console.error('getDisposedStatus failed ' + message); 273} 274``` 275 276## appControl.getDisposedStatusSync<sup>10+</sup> 277 278getDisposedStatusSync(appId: string): Want; 279 280Obtains the disposed status of an application. This API is a synchronous API. If the operation is successful, the disposed status of the application is returned. If the operation fails, an error message is returned. 281 282**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 283 284**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 285 286**System API**: This is a system API. 287 288**Parameters** 289 290| Name | Type | Mandatory | Description | 291| ----------- | ------ | ---- | --------------------------------------- | 292| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 293 294**Return value** 295 296| Type | Description | 297| ------------------------- | ------------------ | 298| Want | Disposed status. | 299 300**Error codes** 301 302For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 303 304| ID| Error Message | 305| ------ | -------------------------------------- | 306| 17700005 | The specified app ID is empty string. | 307 308**Example** 309 310```ts 311import appControl from '@ohos.bundle.appControl'; 312import { BusinessError } from '@ohos.base'; 313import Want from '@ohos.app.ability.Want'; 314 315let appId: string = "com.example.myapplication_xxxxx"; 316let want: Want; 317 318try { 319 want = appControl.getDisposedStatusSync(appId); 320} catch (error) { 321 let message = (error as BusinessError).message; 322 console.error('getDisposedStatusSync failed ' + message); 323} 324``` 325 326## appControl.deleteDisposedStatus 327 328deleteDisposedStatus(appId: string): Promise\<void> 329 330Deletes the disposed status for an application. This API uses a promise to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 331 332**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 333 334**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 335 336**System API**: This is a system API. 337 338**Parameters** 339 340| Name | Type | Mandatory | Description | 341| ----------- | ------ | ---- | --------------------------------------- | 342| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 343 344**Return value** 345 346| Type | Description | 347| ------------------------- | ------------------ | 348| Promise\<void> | Promise that returns no value.| 349 350**Error codes** 351 352For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 353 354| ID| Error Message | 355| ------ | -------------------------------------- | 356| 17700005 | The specified app ID is empty string. | 357 358**Example** 359 360```ts 361import appControl from '@ohos.bundle.appControl'; 362import { BusinessError } from '@ohos.base'; 363 364let appId = "com.example.myapplication_xxxxx"; 365 366try { 367 appControl.deleteDisposedStatus(appId) 368 .then(() => { 369 console.info('deleteDisposedStatus success'); 370 }).catch((error: BusinessError) => { 371 let message = (error as BusinessError).message; 372 console.error('deleteDisposedStatus failed ' + message); 373 }); 374} catch (error) { 375 let message = (error as BusinessError).message; 376 console.error('deleteDisposedStatus failed ' + message); 377} 378``` 379 380## appControl.deleteDisposedStatus 381 382deleteDisposedStatus(appId: string, callback: AsyncCallback\<void>) : void 383 384Deletes the disposed status for an application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 385 386**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 387 388**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 389 390**System API**: This is a system API. 391 392**Parameters** 393 394| Name | Type | Mandatory | Description | 395| ----------- | ------ | ---- | --------------------------------------- | 396| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 397| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object. | 398 399**Error codes** 400 401For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 402 403| ID| Error Message | 404| ------ | -------------------------------------- | 405| 17700005 | The specified app ID is empty string. | 406 407**Example** 408 409```ts 410import appControl from '@ohos.bundle.appControl'; 411import { BusinessError } from '@ohos.base'; 412 413let appId = "com.example.myapplication_xxxxx"; 414try { 415 appControl.deleteDisposedStatus(appId, (error: BusinessError, data) => { 416 if (error) { 417 console.error('deleteDisposedStatus failed ' + error.message); 418 return; 419 } 420 console.info('deleteDisposedStatus success'); 421 }); 422} catch (error) { 423 let message = (error as BusinessError).message; 424 console.error('deleteDisposedStatus failed ' + message); 425} 426``` 427 428## appControl.deleteDisposedStatusSync<sup>10+</sup> 429 430deleteDisposedStatusSync(appId: string) : void 431 432Deletes the disposed status for an application. This API is a synchronous API. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 433 434**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 435 436**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 437 438**System API**: This is a system API. 439 440**Parameters** 441 442| Name | Type | Mandatory | Description | 443| ----------- | ------ | ---- | --------------------------------------- | 444| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 445 446**Error codes** 447 448For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 449 450| ID| Error Message | 451| ------ | -------------------------------------- | 452| 17700005 | The specified app ID is empty string. | 453 454**Example** 455 456```ts 457import appControl from '@ohos.bundle.appControl'; 458import { BusinessError } from '@ohos.base'; 459 460let appId: string = "com.example.myapplication_xxxxx"; 461 462try { 463 appControl.deleteDisposedStatusSync(appId); 464} catch (error) { 465 let message = (error as BusinessError).message; 466 console.error('deleteDisposedStatusSync failed ' + message); 467} 468``` 469 470## Obtaining appId of an Application 471 472**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. It can be obtained by calling [getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo). 473 474**Example** 475 476```ts 477import bundleManager from '@ohos.bundle.bundleManager'; 478import { BusinessError } from '@ohos.base'; 479 480let bundleName = 'com.example.myapplication'; 481let appId: string; 482try { 483 bundleManager.getBundleInfo(bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO) 484 .then((data) => { 485 appId = data.signatureInfo.appId; 486 console.info("appId is " + appId); 487 }).catch((error: BusinessError) => { 488 let message = (error as BusinessError).message; 489 console.error("getBundleInfo failed " + message); 490 }); 491} catch (error) { 492 let message = (error as BusinessError).message; 493 console.error("getBundleInfo failed " + message); 494} 495``` 496