js-apis-appmanager.md 7.1 KB
Newer Older
W
wusongqing 已提交
1 2
# appManager

W
wusongqing 已提交
3 4
> **NOTE**
> 
W
wusongqing 已提交
5
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
6 7 8 9 10 11 12


Implements application management.


## Modules to Import

W
wusongqing 已提交
13

W
wusongqing 已提交
14
```js
W
wusongqing 已提交
15 16 17 18
import app from '@ohos.application.appManager';
```


W
wusongqing 已提交
19
## appManager.isRunningInStabilityTest<sup>8+</sup>
W
wusongqing 已提交
20 21 22

static isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void

W
wusongqing 已提交
23 24 25 26 27
Checks whether this application is undergoing a stability test. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**
W
wusongqing 已提交
28

W
wusongqing 已提交
29 30 31
  | Name| Type| Mandatory| Description| 
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| 
W
wusongqing 已提交
32

W
wusongqing 已提交
33
**Example**
W
wusongqing 已提交
34
    
W
wusongqing 已提交
35
  ```js
W
wusongqing 已提交
36 37
  import app from '@ohos.application.appManager';
  app.isRunningInStabilityTest((err, flag) => {
W
wusongqing 已提交
38
      console.log('startAbility result:' + JSON.stringify(err));
W
wusongqing 已提交
39
  })  
W
wusongqing 已提交
40 41 42
  ```


W
wusongqing 已提交
43
## appManager.isRunningInStabilityTest<sup>8+</sup>
W
wusongqing 已提交
44 45 46

static isRunningInStabilityTest(): Promise&lt;boolean&gt;

W
wusongqing 已提交
47 48 49 50 51
Checks whether this application is undergoing a stability test. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Return value**
W
wusongqing 已提交
52

W
wusongqing 已提交
53 54 55
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| 
W
wusongqing 已提交
56

W
wusongqing 已提交
57
**Example**
W
wusongqing 已提交
58
    
W
wusongqing 已提交
59
  ```js
W
wusongqing 已提交
60 61
  import app from '@ohos.application.appManager';
  app.isRunningInStabilityTest().then((flag) => {
W
wusongqing 已提交
62
      console.log('success:' + JSON.stringify(flag));
W
wusongqing 已提交
63
  }).catch((error) => {
W
wusongqing 已提交
64
      console.log('failed:' + JSON.stringify(error));
W
wusongqing 已提交
65 66
  });
  ```
W
wusongqing 已提交
67 68 69 70 71 72


## appManager.isRamConstrainedDevice

isRamConstrainedDevice(): Promise\<boolean>;

73
Checks whether this application is running on a RAM constrained device. This API uses a promise to return the result.
W
wusongqing 已提交
74 75 76 77 78

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Return value**

W
wusongqing 已提交
79 80 81
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| 
W
wusongqing 已提交
82 83 84 85

**Example**
    
  ```js
W
wusongqing 已提交
86
        app.isRamConstrainedDevice().then((data) => {
W
wusongqing 已提交
87 88 89 90 91 92 93 94 95 96
            console.log('success:' + JSON.stringify(data));
        }).catch((error) => {
            console.log('failed:' + JSON.stringify(error));
        });
  ```

## appManager.isRamConstrainedDevice

isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void;

97
Checks whether this application is running on a RAM constrained device. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
98 99 100 101 102

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

W
wusongqing 已提交
103 104 105
  | Name| Type| Mandatory| Description| 
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| 
W
wusongqing 已提交
106 107 108 109

**Example**
    
  ```js
W
wusongqing 已提交
110
        app.isRamConstrainedDevice((err, data) => {
W
wusongqing 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
            console.log('startAbility result failed:' + JSON.stringify(err));
            console.log('startAbility result success:' + JSON.stringify(data));
        })
  ```

## appManager.getAppMemorySize

getAppMemorySize(): Promise\<number>;

Obtains the memory size of this application. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Return value**

W
wusongqing 已提交
126 127 128
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;number&gt; | Size of the application memory.| 
W
wusongqing 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

**Example**
    
  ```js
        app.getAppMemorySize().then((data) => {
            console.log('success:' + JSON.stringify(data));
        }).catch((error) => {
            console.log('failed:' + JSON.stringify(error));
        });
  ```

## appManager.getAppMemorySize

getAppMemorySize(callback: AsyncCallback\<number>): void;

Obtains the memory size of this application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

W
wusongqing 已提交
150 151 152
  | Name| Type| Mandatory| Description| 
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.| 
W
wusongqing 已提交
153 154 155 156 157 158 159 160 161

**Example**
    
  ```js
        app.getAppMemorySize((err, data) => {
            console.log('startAbility result failed :' + JSON.stringify(err));
            console.log('startAbility result success:' + JSON.stringify(data));
        })
  ```
W
wusongqing 已提交
162 163
## appManager.getProcessRunningInfos<sup>8+</sup>

W
wusongqing 已提交
164
getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>;
W
wusongqing 已提交
165 166 167 168 169 170 171

Obtains information about the running processes. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Return value**

W
wusongqing 已提交
172 173 174
| Type| Description|
| -------- | -------- |
| Promise\<Array\<ProcessRunningInfo>> | Promise used to return the process information.|
W
wusongqing 已提交
175 176 177 178

**Example**
    
  ```js
W
wusongqing 已提交
179
        app.getProcessRunningInfos().then((data) => {
W
wusongqing 已提交
180 181 182 183 184 185 186 187
            console.log('success:' + JSON.stringify(data));
        }).catch((error) => {
            console.log('failed:' + JSON.stringify(error));
        });
  ```

## appManager.getProcessRunningInfos<sup>8+</sup>

W
wusongqing 已提交
188
getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): void;
W
wusongqing 已提交
189 190 191 192 193 194 195

Obtains information about the running processes. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

W
wusongqing 已提交
196 197 198
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<ProcessRunningInfo>> | No| Callback used to return the process information.|
W
wusongqing 已提交
199 200 201 202

**Example**
    
  ```js
W
wusongqing 已提交
203
        app.getProcessRunningInfos((err, data) => {
W
wusongqing 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216 217
            console.log('startAbility result failed :' + JSON.stringify(err));
            console.log('startAbility result success:' + JSON.stringify(data));
        })
  ```

## ProcessRunningInfo

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

| Name       | Readable/Writable| Type                | Mandatory| Description                                                        |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| pid<sup>8+</sup>     | Read only    | number               | No  | Process ID.                               |
| uid<sup>8+</sup>   | Read only    | number               | No  | User ID.|
| processName<sup>8+</sup>  | Read only    | string               | No  | Process name.|
218
| bundleNames<sup>8+</sup>          | Read only    | Array\<string>              | No  | **bundleName** array in the running processes.|