• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle.defaultAppManager (Default Application Management)
2
3The **DefaultAppManager** module provides APIs to query whether the current application is the default application of a specific type.
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## Modules to Import
10
11```ts
12import defaultAppMgr from '@ohos.bundle.defaultAppManager';
13```
14
15## defaultAppMgr.ApplicationType
16
17Enumerates the default application types.
18
19**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
20
21| Name  | Value| Description                                  |
22| -------- | -------------------------------------- | -------------------------------------- |
23| BROWSER  | "Web Browser" | Default browser.                           |
24| IMAGE    | "Image Gallery" | Default image viewer.                        |
25| AUDIO    | "Audio Player" | Default audio player.                        |
26| VIDEO    | "Video Player" | Default video player.                        |
27| PDF      | "PDF Viewer" | Default PDF reader.                     |
28| WORD     | "Word Viewer" | Default Word viewer.                    |
29| EXCEL    | "Excel Viewer" | Default Excel viewer.                   |
30| PPT      | "PPT Viewer" | Default PowerPoint viewer.                     |
31
32## defaultAppMgr.isDefaultApplication
33
34isDefaultApplication(type: string): Promise\<boolean>
35
36Checks whether this application is the default application of a system-defined application type. This API uses a promise to return the result.
37
38**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
39
40**Parameters**
41
42| Name        | Type    | Mandatory  | Description                                     |
43| ----------- | ------ | ---- | --------------------------------------- |
44| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](#defaultappmgrapplicationtype).                          |
45
46**Return value**
47
48| Type                       | Description                |
49| ------------------------- | ------------------ |
50| Promise\<boolean> | Promise used to return the result. If the application is the default application, `true` is returned; otherwise, `false` is returned.|
51
52
53**Example**
54
55```ts
56import defaultAppMgr from '@ohos.bundle.defaultAppManager';
57import { BusinessError } from '@ohos.base';
58
59defaultAppMgr.isDefaultApplication(defaultAppMgr.ApplicationType.BROWSER)
60  .then((data) => {
61    console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data));
62  }).catch((error: BusinessError) => {
63  console.error('Operation failed. Cause: ' + JSON.stringify(error));
64});
65```
66
67## defaultAppMgr.isDefaultApplication
68
69isDefaultApplication(type: string, callback: AsyncCallback\<boolean>): void
70
71Checks whether this application is the default application of a system-defined application type. This API uses an asynchronous callback to return the result.
72
73**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
74
75**Parameters**
76
77| Name        | Type                             | Mandatory  | Description                                     |
78| ----------- | ------------------------------- | ---- | --------------------------------------- |
79| type  | string                          | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](#defaultappmgrapplicationtype).                           |
80| callback    | AsyncCallback\<boolean> | Yes   | Callback used to return the result. If the application is the default application, `true` is returned; otherwise, `false` is returned.|
81
82**Example**
83
84```ts
85import defaultAppMgr from '@ohos.bundle.defaultAppManager';
86import { BusinessError } from '@ohos.base';
87
88defaultAppMgr.isDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err: BusinessError, data) => {
89  if (err) {
90    console.error('Operation failed. Cause: ' + JSON.stringify(err));
91    return;
92  }
93  console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data));
94});
95```
96
97## defaultAppMgr.isDefaultApplicationSync<sup>10+</sup>
98
99isDefaultApplicationSync(type: string): boolean
100
101Checks whether this application is the default application of a system-defined application type. This API is a synchronous API.
102
103**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
104
105**Parameters**
106
107| Name| Type  | Mandatory| Description                                    |
108| -------| ------ | ---- | --------------------------------------- |
109|  type  | string | Yes  | Type of the target application. It must be set to a value defined by [ApplicationType](#defaultappmgrapplicationtype).  |
110
111**Return value**
112
113| Type   | Description                |
114| ------- | -------------------- |
115| boolean | Returns **true** if the application is the default application; returns **false** otherwise.|
116
117
118**Example**
119
120```ts
121import defaultAppMgr from '@ohos.bundle.defaultAppManager';
122try {
123  let data = defaultAppMgr.isDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER)
124  console.info('Operation successful. IsDefaultApplicationSync ? ' + JSON.stringify(data));
125} catch(error) {
126  console.error('Operation failed. Cause: ' + JSON.stringify(error));
127};
128```
129