• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle.defaultAppManager (Default Application Management)
2<!--Kit: Ability Kit-->
3<!--Subsystem: BundleManager-->
4<!--Owner: @wanghang904-->
5<!--Designer: @hanfeng6-->
6<!--Tester: @kongjing2-->
7<!--Adviser: @Brilliantry_Rui-->
8
9The module provides APIs to query whether the current application is the default application of a specific type.
10
11> **NOTE**
12>
13> 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.
14
15## Modules to Import
16
17```ts
18import { defaultAppManager } from '@kit.AbilityKit';
19```
20
21## ApplicationType
22
23Enumerates the default application types.
24
25**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
26
27| Name  | Value| Description                                  |
28| -------- | -------------------------------------- | -------------------------------------- |
29| BROWSER  | 'Web Browser' | Default browser.                           |
30| IMAGE    | 'Image Gallery' | Default image viewer.                        |
31| AUDIO    | 'Audio Player' | Default audio player.                        |
32| VIDEO    | 'Video Player' | Default video player.                        |
33| PDF      | 'PDF Viewer' | Default PDF reader.                     |
34| WORD     | 'Word Viewer' | Default Word viewer.                    |
35| EXCEL    | 'Excel Viewer' | Default Excel viewer.                   |
36| PPT      | 'PPT Viewer' | Default PowerPoint viewer.                     |
37| EMAIL<sup>12+</sup>    | 'Email' | Default email.                     |
38
39## defaultAppManager.isDefaultApplication
40
41isDefaultApplication(type: string): Promise\<boolean>
42
43Checks whether this application is the default application of a system-defined application type or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses a promise to return the result.
44
45**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
46
47**Parameters**
48
49| Name        | Type    | Mandatory  | Description                                     |
50| ----------- | ------ | ---- | --------------------------------------- |
51| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](#applicationtype) or [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).                          |
52
53**Return value**
54
55| Type                       | Description                |
56| ------------------------- | ------------------ |
57| Promise\<boolean> | Promise used to return the result. If the application is the default application, **true** is returned; otherwise, **false** is returned.|
58
59**Error codes**
60
61For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
62
63| ID| Error Message                                                   |
64| -------- | ---------------------------------------------------------- |
65| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
66| 801 | Capability not supported. |
67
68**Example**
69
70```ts
71import { defaultAppManager } from '@kit.AbilityKit';
72import { BusinessError } from '@kit.BasicServicesKit';
73
74defaultAppManager.isDefaultApplication(defaultAppManager.ApplicationType.BROWSER)
75  .then((data) => {
76    console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data));
77  }).catch((error: BusinessError) => {
78    console.error('Operation failed. Cause: ' + JSON.stringify(error));
79  });
80```
81
82## defaultAppManager.isDefaultApplication
83
84isDefaultApplication(type: string, callback: AsyncCallback\<boolean>): void
85
86Checks whether this application is the default application of a system-defined application type or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses an asynchronous callback to return the result.
87
88**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
89
90**Parameters**
91
92| Name        | Type                             | Mandatory  | Description                                     |
93| ----------- | ------------------------------- | ---- | --------------------------------------- |
94| type  | string                          | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](#applicationtype) or [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).                           |
95| callback    | AsyncCallback\<boolean> | Yes   | [Callback](../apis-basic-services-kit/js-apis-base.md#asynccallback) used to return the result. If the application is the default application, **true** is returned; otherwise, **false** is returned.|
96
97**Error codes**
98
99For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
100
101| ID| Error Message                                                   |
102| -------- | ---------------------------------------------------------- |
103| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
104| 801 | Capability not supported. |
105
106**Example**
107
108```ts
109import { defaultAppManager } from '@kit.AbilityKit';
110import { BusinessError } from '@kit.BasicServicesKit';
111
112defaultAppManager.isDefaultApplication(defaultAppManager.ApplicationType.BROWSER, (err: BusinessError, data) => {
113  if (err) {
114    console.error('Operation failed. Cause: ' + JSON.stringify(err));
115    return;
116  }
117  console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data));
118});
119```
120
121## defaultAppManager.isDefaultApplicationSync<sup>10+</sup>
122
123isDefaultApplicationSync(type: string): boolean
124
125Checks whether this application is the default application of a system-defined application type or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API returns the result synchronously.
126
127**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
128
129**Parameters**
130
131| Name| Type  | Mandatory| Description                                    |
132| -------| ------ | ---- | --------------------------------------- |
133|  type  | string | Yes  | Type of the target application. It must be set to a value defined by [ApplicationType](#applicationtype) or [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).  |
134
135**Return value**
136
137| Type   | Description                |
138| ------- | -------------------- |
139| boolean | Returns **true** if the application is the default application; returns **false** otherwise.|
140
141**Error codes**
142
143For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
144
145| ID| Error Message                                                   |
146| -------- | ---------------------------------------------------------- |
147| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
148| 801 | Capability not supported. |
149
150**Example**
151
152```ts
153import { defaultAppManager } from '@kit.AbilityKit';
154
155try {
156  let data = defaultAppManager.isDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER)
157  console.info('Operation successful. IsDefaultApplicationSync ? ' + JSON.stringify(data));
158} catch(error) {
159  console.error('Operation failed. Cause: ' + JSON.stringify(error));
160};
161```
162