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 state 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 and cannot be called by third-party applications. 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 53var appId = "com.example.myapplication_xxxxx"; 54var want = {bundleName: 'com.example.myapplication'}; 55 56try { 57 appControl.setDisposedStatus(appId, want) 58 .then(() => { 59 console.info('setDisposedStatus success'); 60 }).catch((error) => { 61 console.error('setDisposedStatus failed ' + error.message); 62 }); 63} catch (error) { 64 console.error('setDisposedStatus failed ' + error.message); 65} 66``` 67 68## appControl.setDisposedStatus 69 70setDisposedStatus(appId: string, disposedWant: Want, callback: AsyncCallback\<void>): void; 71 72Sets 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. 73 74**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 75 76**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 77 78**System API**: This is a system API and cannot be called by third-party applications. 79 80**Parameters** 81 82| Name | Type | Mandatory | Description | 83| ----------- | ------------------------------- | ---- | --------------------------------------- | 84| 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). | 85| disposedWant | Want | Yes| Disposal intent of the application.| 86| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 87 88**Error codes** 89 90For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 91 92| ID| Error Message | 93| ------ | -------------------------------------- | 94| 17700005 | The specified app ID is empty string. | 95 96**Example** 97 98```ts 99var appId = "com.example.myapplication_xxxxx"; 100var want = {bundleName: 'com.example.myapplication'}; 101 102try { 103 appControl.setDisposedStatus(appId, want, (error, data) => { 104 if (error) { 105 console.error('setDisposedStatus failed ' + error.message); 106 return; 107 } 108 console.info('setDisposedStatus success'); 109 }); 110} catch (error) { 111 console.error('setDisposedStatus failed ' + error.message); 112} 113``` 114 115## appControl.getDisposedStatus 116 117getDisposedStatus(appId: string): Promise\<Want>; 118 119Obtains 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. 120 121**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 122 123**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 124 125**System API**: This is a system API and cannot be called by third-party applications. 126 127**Parameters** 128 129| Name | Type | Mandatory | Description | 130| ----------- | ------ | ---- | --------------------------------------- | 131| 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). | 132 133**Return value** 134 135| Type | Description | 136| ------------------------- | ------------------ | 137| Promise\<Want> | Promise used to return the disposed status.| 138 139**Error codes** 140 141For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 142 143| ID| Error Message | 144| ------ | -------------------------------------- | 145| 17700005 | The specified app ID is empty string. | 146 147**Example** 148 149```ts 150var appId = "com.example.myapplication_xxxxx"; 151 152try { 153 appControl.getDisposedStatus(appId) 154 .then((data) => { 155 console.info('getDisposedStatus success. DisposedStatus: ' + JSON.stringify(data)); 156 }).catch((error) => { 157 console.error('getDisposedStatus failed ' + error.message); 158 }); 159} catch (error) { 160 console.error('getDisposedStatus failed ' + error.message); 161} 162``` 163 164## appControl.getDisposedStatus 165 166getDisposedStatus(appId: string, callback: AsyncCallback\<Want>): void; 167 168Obtains 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. 169 170**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 171 172**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 173 174**System API**: This is a system API and cannot be called by third-party applications. 175 176**Parameters** 177 178| Name | Type | Mandatory | Description | 179| ----------- | ------ | ---- | --------------------------------------- | 180| 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). | 181| callback | AsyncCallback\<Want> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the disposed status obtained; otherwise, **err** is an error object. | 182 183**Error codes** 184 185For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 186 187| ID| Error Message | 188| ------ | -------------------------------------- | 189| 17700005 | The specified app ID is empty string. | 190 191**Example** 192 193```ts 194var appId = "com.example.myapplication_xxxxx"; 195 196try { 197 appControl.getDisposedStatus(appId, (error, data) => { 198 if (error) { 199 console.error('getDisposedStatus failed ' + error.message); 200 return; 201 } 202 console.info('getDisposedStatus success. DisposedStatus: ' + JSON.stringify(data)); 203 }); 204} catch (error) { 205 console.error('getDisposedStatus failed ' + error.message); 206} 207``` 208 209## appControl.deleteDisposedStatus 210 211deleteDisposedStatus(appId: string): Promise\<void> 212 213Deletes 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. 214 215**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 216 217**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 218 219**System API**: This is a system API and cannot be called by third-party applications. 220 221**Parameters** 222 223| Name | Type | Mandatory | Description | 224| ----------- | ------ | ---- | --------------------------------------- | 225| 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). | 226 227**Return value** 228 229| Type | Description | 230| ------------------------- | ------------------ | 231| Promise\<void> | Promise that returns no value.| 232 233**Error codes** 234 235For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 236 237| ID| Error Message | 238| ------ | -------------------------------------- | 239| 17700005 | The specified app ID is empty string. | 240 241**Example** 242 243```ts 244var appId = "com.example.myapplication_xxxxx"; 245 246try { 247 appControl.deleteDisposedStatus(appId) 248 .then(() => { 249 console.info('deleteDisposedStatus success'); 250 }).catch((error) => { 251 console.error('deleteDisposedStatus failed ' + error.message); 252 }); 253} catch (error) { 254 console.error('deleteDisposedStatus failed ' + error.message); 255} 256``` 257 258## appControl.deleteDisposedStatus 259 260deleteDisposedStatus(appId: string, callback: AsyncCallback\<void>) : void 261 262Deletes 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. 263 264**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 265 266**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 267 268**System API**: This is a system API and cannot be called by third-party applications. 269 270**Parameters** 271 272| Name | Type | Mandatory | Description | 273| ----------- | ------ | ---- | --------------------------------------- | 274| 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). | 275| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 276 277**Error codes** 278 279For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 280 281| ID| Error Message | 282| ------ | -------------------------------------- | 283| 17700005 | The specified app ID is empty string. | 284 285**Example** 286 287```ts 288var appId = "com.example.myapplication_xxxxx"; 289try { 290 appControl.deleteDisposedStatus(appId, (error, data) => { 291 if (error) { 292 console.error('deleteDisposedStatus failed ' + error.message); 293 return; 294 } 295 console.info('deleteDisposedStatus success'); 296 }); 297} catch (error) { 298 console.error('deleteDisposedStatus failed ' + error.message); 299} 300``` 301 302## Obtaining appId of an Application 303 304**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). 305 306**Example** 307 308```ts 309import bundleManager from '@ohos.bundle.bundleManager'; 310 311var bundleName = 'com.example.myapplication'; 312var appId; 313try { 314 bundleManager.getBundleInfo(bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO) 315 .then((data) => { 316 appId = data.signatureInfo.appId; 317 console.info("appId is " + appId); 318 }).catch((error) => { 319 console.error("getBundleInfo failed " + error.message); 320 }); 321} catch (error) { 322 console.error("getBundleInfo failed " + error.message); 323} 324``` 325