js-apis-system-app.md 7.5 KB
Newer Older
W
wusongqing 已提交
1 2 3
# Application Context

> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
W
wusongqing 已提交
4
> - The APIs of this module are no longer maintained since API version 7. You are advised to use the new APIs.
W
wusongqing 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
> 
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.


## Modules to Import


```
import app from '@system.app';
```


## app.getInfo

getInfo(): AppResponse

Obtains the declared information in the **config.json** file of an application.

W
wusongqing 已提交
23 24
> **Note: ** [`@ohos.bundle`](js-apis-Bundle.md) is recommended from API version 7.

W
wusongqing 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
**System capability**: SystemCapability.ArkUI.ArkUI.Lite

**Return value**

| Type| Description|
| -------- | -------- |
| [AppResponse](#appresponse) | Application response information.|

**Example**

  ```
  export default {    
    getInfo(){        
      var info = app.getInfo();        
        console.log(JSON.stringify(info));    
    } 
  }
  ```

## app.terminate

terminate(): void

Terminates the current ability.

W
wusongqing 已提交
50 51
> **Note: ** [`@ohos.ability.featureAbility`](js-apis-featureAbility.md) is recommended from API version 7.

W
wusongqing 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
**System capability**: SystemCapability.ArkUI.ArkUI.Lite

**Example**

  ```
  export default {    
    terminate(){        
      app.terminate();    
    }}
  ```
## app.requestFullWindow

requestFullWindow(options?: RequestFullWindowOptions): void

Requests the application to run in full window. You can call this API when the FA runs in a non-full window, for example, semi-modal FA. This API is invalid for an application already in full-window mode.

This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
70 71
> **Note: ** [`@ohos.window`](js-apis-window.md) is recommended from API version 7.

W
wusongqing 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
**System capability**: SystemCapability.ArkUI.ArkUI.Full

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| options | [RequestFullWindowOptions](#requestfullwindowoptions) | No| Duration for transition from the non-full window to the full window, in milliseconds. By default, the value is in direct proportion to the distance between the non-full window and the full window.|

**Example**

  ```
  export default {    
    requestFullWindow(){        
      app.requestFullWindow({            
        duration: 200});    
    }
  }
W
wusongqing 已提交
88
  ```
W
wusongqing 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140

## app.setImageCacheCount<sup>7+</sup>

setImageCacheCount(value: number): void

Sets the maximum number of decoded images that can be cached in the memory to speed up the loading of images from the same sources. If the input parameter is not set, the default value **0** is used, indicating that images are not cached. The built-in Least Recently Used (LRU) policy is used for caching. If the maximum number is exceeded, the images that have not been updated for the longest time will be removed. You are advised to set the parameter based on the application memory requirements. If the number of images is too large, the memory usage may be too high.

**System capability**: SystemCapability.ArkUI.ArkUI.Full

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | No| Number of decoded images that are cached in the memory.|

**Example**

  ```
  // app.ets
  import app from '@system.app';
  
  export default {
      onCreate() { 
          app.setImageCacheCount(100)    // Set the maximum number of decoded images that can be cached in the memory to 100.
          console.info('Application onCreate')
      },
      onDestroy() {
          console.info('Application onDestroy')
      },
  }
  ```

## app.setImageRawDataCacheSize<sup>7+</sup>

setImageRawDataCacheSize(value: number): void

Sets the maximum size (in bytes) of the image data cached in the memory before decoding to speed up the loading of images from the same sources. If the input parameter is not set, the default value **0** is used, indicating that images are not cached. The LRU policy is used for caching. If the maximum size is exceeded, the images that have not been updated for the longest time will be removed. You are advised to set the parameter based on the application memory requirements. If the image cache is too large, the memory usage may be too high.

**System capability**: SystemCapability.ArkUI.ArkUI.Full

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | No| Size of the image data cached before decoding, in bytes.|

**Example**

  ```
  // app.ets
  import app from '@system.app';
  
  export default {
      onCreate() {
W
wusongqing 已提交
141
          app.setImageRawDataCacheSize(100) // Set the upper limit of the memory for caching image data before decoding to 100 MB.
W
wusongqing 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
          console.info('Application onCreate')
      },
      onDestroy() {
          console.info('Application onDestroy')
      },
  }
  ```

## app.setImageFileCacheSize<sup>7+</sup>

setImageFileCacheSize(value: number): void

Sets the maximum size of the image file cache (in bytes) to speed up the loading of images from the same sources, especially online image sources and thumbnails. If the input parameter is not set, the default value 100 MB is used. The LRU policy is used for caching. If the maximum size is exceeded, the images that have not been updated for the longest time will be removed. You are advised to set the parameter based on the application memory requirements. If the image cache is too large, the disk usage may be too high.

**System capability**: SystemCapability.ArkUI.ArkUI.Full

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | No| Size of the image file cache, in bytes.|

**Example**

  ```
  // app.ets
  import app from '@system.app';
  
  export default {  
      onCreate() {    
W
wusongqing 已提交
171
          app.setImageFileCacheSize(200) // Set the upper limit of the image file cache to 200 MB.  
W
wusongqing 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
          console.info('Application onCreate')
      },  
      onDestroy() {
          console.info('Application onDestroy')
      },
  }
  ```

## AppResponse

Defines the application response information.

**System capability**: The items in the table below require different system capabilities. For details, see the table.

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- |-------- |
| appID<sup>6+</sup> | string | Yes| Bundle name of an application. It uniquely identifies the application.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Full|
| appName | string | Yes| Application name.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Lite|
| versionName | string | Yes| Application version name.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Lite|
| versionCode | number | Yes| Application version number.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Lite|

## ScreenOnVisibleOptions

Defines the options of the visible interface on the screen.

**System capability**: SystemCapability.ArkUI.ArkUI.Full

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| visible | boolean | No| Whether to keep the application visible. The default value is **false**.|
| success | () => void | No| Callback upon success.|
| fail | (data: string, code: number) => void | No| Callback upon failure.|
| complete | () => void | No| Called when the API call is complete.|

## RequestFullWindowOptions

Defines the options of the **RequestFullWindow** API.

**System capability**: SystemCapability.ArkUI.ArkUI.Full

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| duration | number | Yes| Number of animation options.|