@ohos.bundle.defaultAppManager (Default Application Management)
The module provides APIs to query whether the current application is the default application of a specific type.
NOTE
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.
Modules to Import
import { defaultAppManager } from '@kit.AbilityKit';
ApplicationType
Enumerates the default application types.
System capability: SystemCapability.BundleManager.BundleFramework.DefaultApp
| Name | Value | Description |
|---|---|---|
| BROWSER | Web Browser | Default browser. |
| IMAGE | Image Gallery | Default image viewer. |
| AUDIO | Audio Player | Default audio player. |
| VIDEO | Video Player | Default video player. |
| PDF Viewer | Default PDF reader. | |
| WORD | Word Viewer | Default Word viewer. |
| EXCEL | Excel Viewer | Default Excel viewer. |
| PPT | PPT Viewer | Default PowerPoint viewer. |
| EMAIL12+ | Default email. |
defaultAppManager.isDefaultApplication
isDefaultApplication(type: string): Promise<boolean>
Checks whether this application is the default application of a system-defined application type or a uniform data type. This API uses a promise to return the result.
System capability: SystemCapability.BundleManager.BundleFramework.DefaultApp
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the target application. It must be set to a value defined by ApplicationType or UniformDataType. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result, indicating whether the application is the default application. true if the application is the default application, false otherwise. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 801 | Capability not supported. |
Example
import { defaultAppManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
defaultAppManager.isDefaultApplication(defaultAppManager.ApplicationType.BROWSER)
.then((data) => {
console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
defaultAppManager.isDefaultApplication
isDefaultApplication(type: string, callback: AsyncCallback<boolean>): void
Checks whether this application is the default application of a system-defined application type or a uniform data type. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.BundleManager.BundleFramework.DefaultApp
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the target application. It must be set to a value defined by ApplicationType or UniformDataType. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, err is null and data is a Boolean value (true if the application is the default application, false otherwise). If the operation fails, err is an error object. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 801 | Capability not supported. |
Example
import { defaultAppManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
defaultAppManager.isDefaultApplication(defaultAppManager.ApplicationType.BROWSER, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data));
});
defaultAppManager.isDefaultApplicationSync10+
isDefaultApplicationSync(type: string): boolean
Checks whether this application is the default application of a system-defined application type or a uniform data type. This API returns the result synchronously.
System capability: SystemCapability.BundleManager.BundleFramework.DefaultApp
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the target application. It must be set to a value defined by ApplicationType or UniformDataType. |
Return value
| Type | Description |
|---|---|
| boolean | Returns true if the application is the default application; returns false otherwise. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 801 | Capability not supported. |
Example
import { defaultAppManager } from '@kit.AbilityKit';
try {
let data = defaultAppManager.isDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER)
console.info('Operation successful. IsDefaultApplicationSync ? ' + JSON.stringify(data));
} catch (error) {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
}