• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Bundle Management Development
2
3
4## How do I determine whether an application is a system application? (API version 9)
5
6**Solution**
7
8Use **bundleManager.getApplicationInfo** (available only for system applications) to obtain application information, and check the value of **systemApp** in the information. The application is a system application if the value is **true**.
9
10**References**
11
12[bundleManager](../reference/apis-ability-kit/js-apis-bundleManager.md)
13
14
15## How do I obtain the version code and version name of an application? (API version 9)
16
17**Solution**
18
19Use **bundleManager.getBundleInfoForSelf()** to obtain the bundle information, which contains the version code (specified by **BundleInfo.versionCode**) and version name (specified by **BundleInfo.versionName**) .
20
21**Example**
22
23```
24import bundleManager from '@ohos.bundle.bundleManager';
25import hilog from '@ohos.hilog';
26let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
27try {
28  bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
29    const versionCode = data.versionCode;
30    const versionName = data.versionName;
31    hilog.info(0x0000, 'testTag', `successfully. versionCode: ${versionCode}, versionName: ${versionName}`);
32  }).catch(err => {
33    hilog.error(0x0000, 'testTag', 'failed. Cause: %{public}s', err.message);
34  });
35} catch (err) {
36  hilog.error(0x0000, 'testTag', 'failed: %{public}s', err.message);
37}
38```
39
40**References**
41
42[getBundleInfoForSelf](../reference/apis-ability-kit/js-apis-bundleManager.md#bundlemanagergetbundleinfoforself)
43
44
45## How do I obtain the bundle name of the current application? (API version 9)
46
47**Solution**
48
49Obtain the bundle name from **UIAbilityContext.abilityInfo.bundleName**.
50
51**Example**
52
53```
54import common from '@ohos.app.ability.common';
55const context = getContext(this) as common.UIAbilityContext
56console.log(`bundleName: ${context.abilityInfo.bundleName}`)
57```
58
59**References**
60
61[UIAbilityContext](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) and [AbilityInfo](../reference/apis-ability-kit/js-apis-bundleManager-abilityInfo.md)
62
63
64## How do I obtain the application version number, version name, and screen resolution? (API version 9)
65
66**Solution**
67
681. Obtain the bundle information from the **\@ohos.bundle.bundleManager** module.
69
70   The bundle information contains the application version number and version name.
71
72   ```
73   import bundleManager from '@ohos.bundle.bundleManager';
74   ...
75   bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo)=>{
76     let versionName = bundleInfo.versionName; // Application version name.
77     let versionNo = bundleInfo.versionCode; // Application version number.
78   }).catch((error)=>{
79     console.error("get bundleInfo failed,error is "+error)
80   })
81   ```
82
832. Obtain **screenDensity** from the **\@ohos.app.ability.Configuration** module. **screenDensity** contains the screen resolution information.
84
85   ```
86   import common from '@ohos.app.ability.common';
87   ...
88   let context = getContext(this) as common.UIAbilityContext;
89   let screenDensity = context.config.screenDensity;
90   ```
91
92
93## How do I obtain the source file path of the current application? (API version 9)
94
95**Solution**
96
97- Method 1: Use the application context to obtain the source file path.
98
99  ```
100  this.uiAbilityContext.abilityInfo.applicationInfo.codePath
101  ```
102
103- Method 2: Use **\@ohos.bundle.bundleManager** to obtain the source file path.
104
105  1. Import the **\@ohos.bundle.bundleManager** module and use **bundleManager.getBundleInfoForSelf()** to obtain the bundle information.
106  2. Obtain the source file path from **bundleInfo.appInfo.codePath**.
107
108  ```
109  import bundleManager from '@ohos.bundle.bundleManager';
110  bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo)=>{
111    this.sourcePath = bundleInfo.appInfo.codePath;
112  })
113  ```
114
115
116## Can I obtain the HAP information of other applications from the current application? (API version 9)
117
118**Symptom**
119
120
121
122**Solution**
123
124Currently, only system applications can call the API to query information about other applications.
125
126- To query information about an application in the system, you must obtain the normal-level permission **ohos.permission.GET_BUNDLE_INFO** and call the **bundleManager.getApplicationInfo()** API.
127
128- To query information about all applications in the system, you must obtain the **system_basic**-level permission **ohos.permission.GET_BUNDLE_INFO_PRIVILEGED** and call the **bundleManager.getAllApplicationInfo()** API.
129
130**References**
131
132[@ohos.bundle.bundleManager \(bundleManager\)](../reference/apis-ability-kit/js-apis-bundleManager.md)
133
134
135## How do I query the PID of a process? (API version 9)
136
137**Solution**
138
139You can obtain the PID through the **\@ohos.process** interface.
140
141**Example**
142
143```
144import process from '@ohos.process';
145private pid = process.pid;
146```
147
148**References**
149
150[@ohos.process (Obtaining Process Information)](../reference/apis-arkts/js-apis-process.md)
151
152
153## How do I disable the maximize button? (API version 9)
154
155**Solution**
156
157You can use the **supportWindowModes** field to specify whether to display the maximize button.
158
159- **full_screen** means that a window in full-screen mode is supported.
160
161- **split** means that a window in split-screen mode is supported.
162
163- **floating** means that a floating window is supported.
164
165**Example**
166
167```
168"abilities": [
169  {
170    "name": "EntryAbility",
171    "srcEntry": "./ets/entryability/EntryAbility.ets",
172    "description": "$string:EntryAbility_desc",
173    "icon": "$media:icon",
174    "label": "$string:EntryAbility_label",
175    "startWindowIcon": "$media:icon",
176    "startWindowBackground": "$color:start_window_background",
177    "exported": true,
178    "supportWindowMode": ["split", "floating"],
179    "skills": [
180      {
181        "entities": [
182          "entity.system.home"
183        ],
184        "actions": [
185          "action.system.home"
186        ]
187      }
188    ]
189  }
190]
191```
192
193**References**
194
195[supportWindowModes](../reference/apis-ability-kit/js-apis-bundleManager-abilityInfo.md)
196