未验证 提交 cec9fa72 编写于 作者: O openharmony_ci 提交者: Gitee

!3114 新增英文system api文档

Merge pull request !3114 from zengyawen/master
......@@ -222,8 +222,20 @@
- [@ohos.bytrace](js-apis-bytrace.md)
- [@ohos.data.storage](js-apis-data-storage.md)
- [@system.app](js-apis-system-app.md)
- [@system.battery](js-apis-system-battery.md)
- [@system.brightness](js-apis-system-brightness.md)
- [@system.configuration](js-apis-system-configuration.md)
- [@system.device](js-apis-system-device.md)
- [@system.fetch](js-apis-system-fetch.md)
- [@system.file](js-apis-system-file.md)
- [@system.geolocation](js-apis-system-location.md)
- [@system.mediaquery](js-apis-system-mediaquery.md)
- [@system.network](js-apis-system-network.md)
- [@system.package](js-apis-system-package.md)
- [@system.prompt](js-apis-system-prompt.md)
- [@system.request](js-apis-system-request.md)
- [@system.router](js-apis-system-router.md)
- [@system.sensor](js-apis-system-sensor.md)
- [@system.storage](js-apis-system-storage.md)
- [@system.vibrator](js-apis-system-vibrate.md)
- [console](js-apis-logs.md)
\ No newline at end of file
# Battery Level
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.batteryInfo`](js-apis-battery-info.md) instead.
>
> - 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 battery from '@system.battery';
```
## battery.getStatus
getStatus(Object): void
Obtains the current charging state and battery level.
**System capability**: SystemCapability.PowerManager.BatteryManager.Core
**Parameter**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| success | Function | No | Called when the check result is obtained |
| fail | Function | No | Called when the check result fails to be obtained |
| complete | Function | No | Called when the execution is complete |
The following value will be returned when the check result is obtained.
| Name | Type | Description |
| -------- | -------- | -------- |
| charging | boolean | Whether the battery is being charged |
| level | number | Current battery level, which ranges from 0.00 to 1.00. |
**Example**
```
export default {
getStatus() {
battery.getStatus({
success: function(data) {
console.log('success get battery level:' + data.level);
},
fail: function(data, code) {
console.log('fail to get battery level code:' + code + ', data: ' + data);
},
});
},
}
```
\ No newline at end of file
# Screen Brightness
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.brightness`](js-apis-brightness.md) instead.
>
> - 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 brightness from '@system.brightness';
```
## brightness.getValue
getValue(Object): void
Obtains the current screen brightness.
**System capability**: SystemCapability.PowerManager.DisplayPowerManager
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| success | Function | No | Called when the execution is successful. |
| fail | Function | No | Called when the operation fails. |
| complete | Function | No | Called when the execution is complete |
The following values will be returned when the operation is successful.
| Name | Type | Description |
| -------- | -------- | -------- |
| value | number | Screen brightness, which ranges from 1 to 255. |
**Example**
```
export default {
getValue() {
brightness.getValue({
success: function(data){
console.log('success get brightness value:' + data.value);
},
fail: function(data, code) {
console.log('get brightness fail, code: ' + code + ', data: ' + data);
},
});
},
}
```
## brightness.setValue
setValue(Object): void
Sets the screen brightness.
**System capability**: SystemCapability.PowerManager.DisplayPowerManager
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| value | number | Yes | Screen&nbsp;brightness.&nbsp;The&nbsp;value&nbsp;is&nbsp;an&nbsp;integer&nbsp;ranging&nbsp;from&nbsp;1&nbsp;to&nbsp;255.<br/>-&nbsp;If&nbsp;the&nbsp;value&nbsp;is&nbsp;less&nbsp;than&nbsp;or&nbsp;equal&nbsp;to&nbsp;**0**,&nbsp;value&nbsp;**1**&nbsp;will&nbsp;be&nbsp;used.<br/>-&nbsp;If&nbsp;the&nbsp;value&nbsp;is&nbsp;greater&nbsp;than&nbsp;**255**,&nbsp;value&nbsp;**255**&nbsp;will&nbsp;be&nbsp;used.<br/>-&nbsp;If&nbsp;the&nbsp;value&nbsp;contains&nbsp;decimals,&nbsp;the&nbsp;integral&nbsp;part&nbsp;of&nbsp;the&nbsp;value&nbsp;will&nbsp;be&nbsp;used.&nbsp;For&nbsp;example,&nbsp;if&nbsp;value&nbsp;**8.1**&nbsp;is&nbsp;set,&nbsp;value&nbsp;**8**&nbsp;will&nbsp;be&nbsp;used. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example**
```
export default {
setValue() {
brightness.setValue({
value: 100,
success: function(){
console.log('handling set brightness success.');
},
fail: function(data, code){
console.log('handling set brightness value fail, code:' + code + ', data: ' + data);
},
});
},
}
```
## brightness.getMode
getMode(Object): void
Obtains the screen brightness adjustment mode.
**System capability**: SystemCapability.PowerManager.DisplayPowerManager
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete |
The following values will be returned when the operation is successful.
| Name | Type | Description |
| -------- | -------- | -------- |
| mode | number | The&nbsp;value&nbsp;can&nbsp;be&nbsp;**0**&nbsp;or&nbsp;**1**.<br/>-&nbsp;**0**:&nbsp;The&nbsp;screen&nbsp;brightness&nbsp;is&nbsp;manually&nbsp;adjusted.<br/>-&nbsp;**1**:&nbsp;The&nbsp;screen&nbsp;brightness&nbsp;is&nbsp;automatically&nbsp;adjusted. |
**Example**
```
export default {
getMode() {
brightness.getMode({
success: function(data){
console.log('success get mode:' + data.mode);
},
fail: function(data, code){
console.log('handling get mode fail, code:' + code + ', data: ' + data);
},
});
},
}
```
## brightness.setMode
setMode(Object): void
Sets the screen brightness adjustment mode.
**System capability**: SystemCapability.PowerManager.DisplayPowerManager
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| mode | number | Yes | The&nbsp;value&nbsp;can&nbsp;be&nbsp;**0**&nbsp;or&nbsp;**1**.<br/>-&nbsp;**0**:&nbsp;The&nbsp;screen&nbsp;brightness&nbsp;is&nbsp;manually&nbsp;adjusted.<br/>-&nbsp;**1**:&nbsp;The&nbsp;screen&nbsp;brightness&nbsp;is&nbsp;automatically&nbsp;adjusted. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example**
```
export default {
setMode() {
brightness.setMode({
mode: 1,
success: function(){
console.log('handling set mode success.');
},
fail: function(data, code){
console.log('handling set mode fail, code:' + code + ', data: ' + data);
},
});
},
}
```
## brightness.setKeepScreenOn
setKeepScreenOn(Object): void
Sets whether to always keep the screen on. Call this API in **onShow()**.
**System capability**: SystemCapability.PowerManager.DisplayPowerManager
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| keepScreenOn | boolean | Yes | Whether&nbsp;to&nbsp;always&nbsp;keep&nbsp;the&nbsp;screen&nbsp;on |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example**
```
export default {
setKeepScreenOn() {
brightness.setKeepScreenOn({
keepScreenOn: true,
success: function () {
console.log('handling set keep screen on success.')
},
fail: function (data, code) {
console.log('handling set keep screen on fail, code:' + code + ', data: ' + data);
},
});
},
}
```
\ No newline at end of file
# Encryption Algorithm
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
>
> - 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.
> - This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
## Modules to Import
```
import cipher from '@system.cipher'
```
## cipher.rsa
rsa(Object): void
Encrypts or decrypts data using RSA.
**System capability**: SystemCapability.Security.Cipher
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| action | string | Yes | Action&nbsp;type.&nbsp;The&nbsp;options&nbsp;are&nbsp;as&nbsp;follows:<br/>1.&nbsp;**encrypt**:&nbsp;Encrypts&nbsp;data.<br/>2.&nbsp;**decrypt**:&nbsp;Decrypts&nbsp;data. |
| text | string | Yes | Text&nbsp;content&nbsp;to&nbsp;be&nbsp;encrypted&nbsp;or&nbsp;decrypted.&nbsp;The&nbsp;text&nbsp;to&nbsp;be&nbsp;encrypted&nbsp;must&nbsp;be&nbsp;a&nbsp;common&nbsp;text&nbsp;and&nbsp;cannot&nbsp;exceed&nbsp;the&nbsp;length&nbsp;calculated&nbsp;based&nbsp;on&nbsp;the&nbsp;formula&nbsp;(keySize/8&nbsp;-&nbsp;66).&nbsp;**keySize**&nbsp;indicates&nbsp;the&nbsp;key&nbsp;length.&nbsp;For&nbsp;example,&nbsp;if&nbsp;the&nbsp;key&nbsp;length&nbsp;is&nbsp;1024&nbsp;bytes,&nbsp;the&nbsp;text&nbsp;cannot&nbsp;exceed&nbsp;62&nbsp;bytes&nbsp;(1024/8&nbsp;-&nbsp;66&nbsp;=&nbsp;62).&nbsp;The&nbsp;text&nbsp;content&nbsp;to&nbsp;be&nbsp;decrypted&nbsp;must&nbsp;be&nbsp;a&nbsp;binary&nbsp;value&nbsp;encoded&nbsp;using&nbsp;Base64.&nbsp;The&nbsp;default&nbsp;format&nbsp;is&nbsp;used&nbsp;for&nbsp;Base64&nbsp;encoding. |
| key | string | Yes | Keys&nbsp;encrypted&nbsp;using&nbsp;RSA.&nbsp;During&nbsp;encryption,&nbsp;this&nbsp;parameter&nbsp;is&nbsp;a&nbsp;public&nbsp;key.&nbsp;During&nbsp;decryption,&nbsp;it&nbsp;is&nbsp;a&nbsp;private&nbsp;key. |
| transformation | string | No | RSA&nbsp;algorithm&nbsp;padding.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**RSA/None/OAEPWithSHA256AndMGF1Padding**. |
| success | Function | No | Called&nbsp;when&nbsp;data&nbsp;is&nbsp;encrypted&nbsp;or&nbsp;decrypted&nbsp;successfully. |
| fail | Function | No | Called&nbsp;when&nbsp;data&nbsp;fails&nbsp;to&nbsp;be&nbsp;encrypted&nbsp;or&nbsp;decrypted. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example**
```
export default {
rsa() {
cipher.rsa({
// Encrypt data.
action: 'encrypt',
// Text content to be encrypted
text: 'hello',
// Base64-encoded public key used for encryption
key:
'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDc7GR2MrfAoefES+wrs1ns2afT\n' +
'eJXSfIkEHfPXG9fVFjaws1ho4KcZfsxlA0+SXvc83f2SVGCuzULmM2lxxRCtcUN/\n' +
'h7SoaYEeluhqFimL2AEjfSwINHCLqObJkcjCfoZpE1JCehPiDOJsyT50Auc08h/4\n' +
'jHQfanyC1nc62LqUCQIDAQAB',
success: function(data) {
console.log('handling success: ${data.text}');
},
fail: function(data, code) {
console.log(`### cipher.rsa encrypt fail ### ${code}: ${data}`);
}
});
cipher.rsa({
// Decrypt data.
action: 'decrypt',
// The text to be decrypted is a Base64-encoded binary value, and the decrypted text is "hello".
text:
'CUg3tTxTIdpCfreIxIBdws3uhd5qXLwcrVl3XDnQzZFVHyjVVCDHS16rjopaZ4C5xU2Tc8mSDzt7\n' +
'gp9vBfSwi7bMtSUvXG18DlncsKJFDkJpS5t0PkpS9YrJXrY80Gpe+ME6+6dN9bjgqMljbitDdBRf\n' +
'S/ZWNI4Q8Q0suNjNkGU=',
// Base64-encoded public key used for encryption
key:
'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANzsZHYyt8Ch58RL\n' +
'7CuzWezZp9N4ldJ8iQQd89cb19UWNrCzWGjgpxl+zGUDT5Je9zzd/ZJUYK7NQuYz\n' +
'aXHFEK1xQ3+HtKhpgR6W6GoWKYvYASN9LAg0cIuo5smRyMJ+hmkTUkJ6E+IM4mzJ\n' +
'PnQC5zTyH/iMdB9qfILWdzrYupQJAgMBAAECgYEAkibhH0DWR13U0gvYJeD08Lfd\n' +
'Sw1PMHyquEqIcho9Yv7bF3LOXjOg2EEGPx09mvuwXFgP1Kp1e67XPytr6pQQPzK7\n' +
'XAPcLPx80R/ZjZs8vNFndDOd1HgD3vSVmYQarNzmKi72tOUWMPevsaFXPHo6Xx3X\n' +
'8x0wYb7XuBsQguRctTECQQD7GWX3JUiyo562iVrpTDPOXsrUxmzCrgz2OZildxMd\n' +
'Pp/PkyDrx7mEXTpk4K/XnQJ3GpJNi2iDSxDuPSAeJ/aPAkEA4Tw4+1Z43S/xH3C3\n' +
'nfulYBNyB4si6KEUuC0krcC1pDJ21Gd12efKo5VF8SaJI1ZUQOzguV+dqNsB/JUY\n' +
'OFfX5wJAB1dKv9r7MR3Peg6x9bggm5vx2h6i914XSuuMJupASM6X5X2rrLj+F3yS\n' +
'RHi9K1SPyeOg+1tkBtKfABgRZFBOyQJAbuTivUSe73AqTKuHjB4ZF0ubqgEkJ9sf\n' +
'Q2rekzm9dOFvxjZGPQo1qALX09qATMi1ZN376ukby8ZAnSafLSZ64wJBAM2V37go\n' +
'Sj44HF76ksRow8gecuQm48NCTGAGTicXg8riKog2GC9y8pMNHAezoR9wXJF7kk+k\n' +
'lz5cHyoMZ9mcd30=',
success: function(data) {
console.log('handling success: ${data.text}');
},
fail: function(data, code) {
console.log(`### cipher.rsa decrypt fail ### ${code}: ${data}`);
},
});
}
}
```
## cipher.aes
aes(Object): void
Encrypts or decrypts data using AES.
**System capability**: SystemCapability.Security.Cipher
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| action | string | Yes | Action&nbsp;type.&nbsp;The&nbsp;options&nbsp;are&nbsp;as&nbsp;follows:<br/>1.&nbsp;**encrypt**:&nbsp;Encrypts&nbsp;data.<br/>2.&nbsp;**decrypt**:&nbsp;Decrypts&nbsp;data. |
| text | string | Yes | Text&nbsp;content&nbsp;to&nbsp;be&nbsp;encrypted&nbsp;or&nbsp;decrypted.&nbsp;The&nbsp;text&nbsp;to&nbsp;be&nbsp;encrypted&nbsp;must&nbsp;be&nbsp;a&nbsp;common&nbsp;text.&nbsp;The&nbsp;text&nbsp;content&nbsp;to&nbsp;be&nbsp;decrypted&nbsp;must&nbsp;be&nbsp;a&nbsp;binary&nbsp;value&nbsp;encoded&nbsp;using&nbsp;Base64.&nbsp;The&nbsp;default&nbsp;format&nbsp;is&nbsp;used&nbsp;for&nbsp;Base64&nbsp;encoding. |
| key | string | Yes | Key&nbsp;used&nbsp;for&nbsp;encryption&nbsp;or&nbsp;decryption,&nbsp;which&nbsp;is&nbsp;a&nbsp;character&nbsp;string&nbsp;encrypted&nbsp;using&nbsp;Base64. |
| transformation | string | No | Encryption&nbsp;mode&nbsp;and&nbsp;padding&nbsp;of&nbsp;the&nbsp;AES&nbsp;algorithm.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**AES/CBC/PKCS5Padding**. |
| iv | string | No | Initial&nbsp;vector&nbsp;for&nbsp;AES-based&nbsp;encryption&nbsp;and&nbsp;decryption.&nbsp;The&nbsp;value&nbsp;is&nbsp;a&nbsp;character&nbsp;string&nbsp;encoded&nbsp;using&nbsp;Base64.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;the&nbsp;key&nbsp;value. |
| ivOffset | string | No | Offset&nbsp;of&nbsp;the&nbsp;initial&nbsp;vector&nbsp;for&nbsp;AES-based&nbsp;encryption&nbsp;and&nbsp;decryption.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**0**. |
| ivLen | string | No | Length&nbsp;of&nbsp;the&nbsp;initial&nbsp;vector&nbsp;for&nbsp;AES-based&nbsp;encryption&nbsp;and&nbsp;decryption.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**16**. |
| success | Function | No | Called&nbsp;when&nbsp;data&nbsp;is&nbsp;encrypted&nbsp;or&nbsp;decrypted&nbsp;successfully. |
| fail | Function | No | Called&nbsp;when&nbsp;data&nbsp;fails&nbsp;to&nbsp;be&nbsp;encrypted&nbsp;or&nbsp;decrypted. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example**
```
export default {
aes() {
cipher.aes({
// Encrypt data.
action: 'encrypt',
// Text content to be encrypted
text: 'hello',
// Base64-encoded key used for encryption
key: 'NDM5Qjk2UjAzMEE0NzVCRjlFMkQwQkVGOFc1NkM1QkQ=',
transformation: 'AES/CBC/PKCS5Padding',
ivOffset: 0,
ivLen: 16,
success: (data) => {
console.log('handling success: ${data.text}');
},
fail: (data, code) => {
console.log(`### cipher.aes encrypt fail ### ${code}: ${data}`);
}
});
cipher.aes({
// Decrypt data.
action: 'decrypt',
// Text to be decrypted, which is a Base64-encoded binary value
text: 'CUg3tTxTIdpCfreIxIBdws3uhd5qXLwcrVl3XDnQzZFVHyjVVCDHS16rjopaZ4C5xU2Tc8mSDzt7\n' +
'gp9vBfSwi7bMtSUvXG18DlncsKJFDkJpS5t0PkpS9YrJXrY80Gpe+ME6+6dN9bjgqMljbitDdBRf\n' +
'S/ZWNI4Q8Q0suNjNkGU=',
// Base64-encoded key used for decryption
key: 'NDM5Qjk2UjAzMEE0NzVCRjlFMkQwQkVGOFc1NkM1QkQ=',
transformation: 'AES/CBC/PKCS5Padding',
ivOffset: 0,
ivLen: 16,
success: (data) => {
this.dealTxt = data.text;
},
fail: (data, code) => {
prompt.showToast({
message: (`### cipher.aes decrypt fail ### code = ${code}: ${data}`)
})
},
});
}
}
```
\ No newline at end of file
# Application Configuration
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.i18n`](js-apis-i18n.md) and [`@ohos.intl`](js-apis-intl.md) instead.
>
>
> - 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 configuration from '@system.configuration';
```
## configuration.getLocale
getLocale(): &lt;LocaleResponse&gt;
Obtains the current locale of the application, which is the same as the system locale.
**System capability**: SystemCapability.ArkUI.ArkUI.Lite
**Return values**
**Table 1** LocaleResponse
| Name | Type | Description |
| -------- | -------- | -------- |
| language | string | Current&nbsp;language&nbsp;of&nbsp;the&nbsp;application,&nbsp;for&nbsp;example,&nbsp;**zh**. |
| countryOrRegion | string | Country&nbsp;or&nbsp;region,&nbsp;for&nbsp;example,&nbsp;**CN**. |
| dir | string | Text&nbsp;layout&nbsp;direction.&nbsp;Available&nbsp;values&nbsp;are&nbsp;as&nbsp;follows:<br/>-&nbsp;**ltr**:&nbsp;The&nbsp;text&nbsp;direction&nbsp;is&nbsp;from&nbsp;left&nbsp;to&nbsp;right.<br/>-&nbsp;**rtl**:&nbsp;The&nbsp;text&nbsp;direction&nbsp;is&nbsp;from&nbsp;right&nbsp;to&nbsp;left. |
| unicodeSetting<sup>5+</sup> | string | Unicode&nbsp;key&nbsp;set&nbsp;determined&nbsp;by&nbsp;the&nbsp;locale.<br/>For&nbsp;example,&nbsp;**{"nu":"arab"}**&nbsp;indicates&nbsp;that&nbsp;the&nbsp;current&nbsp;locale&nbsp;uses&nbsp;Arabic&nbsp;numerals.<br/>If&nbsp;the&nbsp;current&nbsp;locale&nbsp;does&nbsp;not&nbsp;have&nbsp;a&nbsp;specific&nbsp;key&nbsp;set,&nbsp;an&nbsp;empty&nbsp;set&nbsp;is&nbsp;returned. |
**Example**
```
export default {
getLocale() {
const localeInfo = configuration.getLocale();
console.info(localeInfo.language);
}
}
```
\ No newline at end of file
# Device Information
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.deviceInfo`](js-apis-device-info.md) instead.
>
> - 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 device from '@system.device';
```
## device.getInfo
getInfo(Object): void
Obtains the device information.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> Do not call **device.getInfo** before the **onShow** event of the home page.
**System capability**: SystemCapability.Startup.SysInfo
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;device&nbsp;information&nbsp;is&nbsp;obtained |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;device&nbsp;information&nbsp;fails&nbsp;to&nbsp;be&nbsp;obtained |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete |
The following values will be returned when the device information is obtained.
| Name | Type | Description |
| -------- | -------- | -------- |
| brand | string | Brand |
| manufacturer | string | Manufacturer |
| model | string | Model |
| product | string | Product&nbsp;number |
| language<sup>4+</sup> | string | System&nbsp;language |
| region<sup>4+</sup> | string | System&nbsp;region |
| windowWidth | number | Window&nbsp;width |
| windowHeight | number | Window&nbsp;height |
| screenDensity<sup>4+</sup> | number | Screen&nbsp;density |
| screenShape<sup>4+</sup> | string | Screen&nbsp;shape.&nbsp;The&nbsp;options&nbsp;are&nbsp;as&nbsp;follows:<br/>-&nbsp;rect:&nbsp;rectangle&nbsp;screen<br/>-&nbsp;circle:&nbsp;circle&nbsp;screen |
| apiVersion<sup>4+</sup> | number | API&nbsp;version |
| releaseType<sup>4+</sup> | string | Release&nbsp;type.&nbsp;The&nbsp;value&nbsp;includes&nbsp;both&nbsp;the&nbsp;release&nbsp;type&nbsp;and&nbsp;the&nbsp;API&nbsp;version,&nbsp;for&nbsp;example,&nbsp;Beta1.<br/>Available&nbsp;release&nbsp;types&nbsp;are&nbsp;as&nbsp;follows:<br/>-&nbsp;**Canary**:&nbsp;For&nbsp;the&nbsp;same&nbsp;API&nbsp;version,&nbsp;different&nbsp;canary&nbsp;releases&nbsp;are&nbsp;compatible&nbsp;with&nbsp;each&nbsp;other,&nbsp;but&nbsp;not&nbsp;compatible&nbsp;with&nbsp;those&nbsp;of&nbsp;the&nbsp;**beta**&nbsp;and&nbsp;**release**&nbsp;type.<br/>-&nbsp;**Beta**:&nbsp;For&nbsp;the&nbsp;same&nbsp;API&nbsp;version,&nbsp;different&nbsp;beta&nbsp;releases&nbsp;are&nbsp;compatible&nbsp;with&nbsp;each&nbsp;other,&nbsp;but&nbsp;not&nbsp;compatible&nbsp;with&nbsp;those&nbsp;of&nbsp;the&nbsp;**release**&nbsp;type.<br/>-&nbsp;**Release**:&nbsp;Releases&nbsp;of&nbsp;this&nbsp;type&nbsp;are&nbsp;compatible&nbsp;with&nbsp;the&nbsp;latest&nbsp;five&nbsp;API&nbsp;versions. |
| deviceType<sup>4+</sup> | string | Device type |
The following error code will be returned if the device information fails to be obtained.
| Error&nbsp;Code | Description |
| -------- | -------- |
| 200 | The&nbsp;returned&nbsp;result&nbsp;contains&nbsp;information&nbsp;that&nbsp;cannot&nbsp;be&nbsp;obtained. |
**Example**
```
export default {
getInfo() {
device.getInfo({
success: function(data) {
console.log('Device information obtained successfully. Device brand:' + data.brand);
},
fail: function(data, code) {
console.log('Failed to obtain device information. Error code:'+ code + '; Error information: ' + data);
},
});
},
}
```
\ No newline at end of file
# Data Request
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.net.http`](js-apis-http.md) instead.
>
> - 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 fetch from '@system.fetch';
```
## fetch.fetch
fetch(Object): void
Obtains data through a network.
**Required permissions:** ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| url | string | Yes | Resource&nbsp;URL. |
| data | string \| Object | No | Request&nbsp;parameter,&nbsp;which&nbsp;can&nbsp;be&nbsp;a&nbsp;string&nbsp;or&nbsp;a&nbsp;JSON&nbsp;object. For details, see Relationship between data and Content-Type. |
| header | Object | No | Request&nbsp;header. |
| method | string | No | Request&nbsp;method.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**GET**.&nbsp;The&nbsp;value&nbsp;can&nbsp;be&nbsp;**OPTIONS**,&nbsp;**GET**,&nbsp;**HEAD**,&nbsp;**POST**,&nbsp;**PUT**,&nbsp;**DELETE&nbsp;**or&nbsp;**TRACE**. |
| responseType | string | No | Response&nbsp;type.&nbsp;The&nbsp;return&nbsp;type&nbsp;can&nbsp;be&nbsp;text&nbsp;or&nbsp;JSON.&nbsp;By&nbsp;default,&nbsp;the&nbsp;return&nbsp;type&nbsp;is&nbsp;determined&nbsp;based&nbsp;on&nbsp;**Content-Type**&nbsp;in&nbsp;the&nbsp;header&nbsp;returned&nbsp;by&nbsp;the&nbsp;server.&nbsp;For&nbsp;details,&nbsp;see return values of the success callback. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;network&nbsp;data&nbsp;is&nbsp;obtained&nbsp;successfully. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;network&nbsp;data&nbsp;fails&nbsp;to&nbsp;be&nbsp;obtained. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Table1** Relationship between data and Content-Type
| data | Content-Type | Description |
| -------- | -------- | -------- |
| string | Not&nbsp;set | The&nbsp;default&nbsp;value&nbsp;of&nbsp;Content-Type&nbsp;is&nbsp;text/plain,&nbsp;and&nbsp;the&nbsp;value&nbsp;of&nbsp;data&nbsp;is&nbsp;used&nbsp;as&nbsp;the&nbsp;request&nbsp;body. |
| string | Any&nbsp;type | The&nbsp;value&nbsp;of&nbsp;data&nbsp;is&nbsp;used&nbsp;as&nbsp;the&nbsp;request&nbsp;body. |
| Object | Not&nbsp;set | The&nbsp;default&nbsp;value&nbsp;of&nbsp;**Content-Type**&nbsp;is&nbsp;**application/x-www-form-urlencoded**.&nbsp;The&nbsp;**data**&nbsp;value&nbsp;is&nbsp;encoded&nbsp;based&nbsp;on&nbsp;the&nbsp;URL&nbsp;rule&nbsp;and&nbsp;appended&nbsp;in&nbsp;the&nbsp;request&nbsp;body. |
| Object | application/x-www-form-urlencoded | The&nbsp;value&nbsp;of&nbsp;data&nbsp;is&nbsp;encoded&nbsp;based&nbsp;on&nbsp;the&nbsp;URL&nbsp;rule&nbsp;and&nbsp;is&nbsp;used&nbsp;as&nbsp;the&nbsp;request&nbsp;body. |
The following values will be returned when data is successfully obtained.
| Parameter | Type | Description |
| -------- | -------- | -------- |
| code | number | Server&nbsp;status&nbsp;code. |
| data | string \| Object | The&nbsp;type&nbsp;of&nbsp;the&nbsp;returned&nbsp;data&nbsp;is&nbsp;determined&nbsp;by&nbsp;**responseType**.&nbsp;For&nbsp;details,&nbsp;see&nbsp;Relationship between responseType and data returned by the success function. |
| headers | Object | All&nbsp;headers&nbsp;in&nbsp;the&nbsp;response&nbsp;from&nbsp;the&nbsp;server. |
**Table2** Relationship between responseType and data returned by the success function
| responseType | data | Description |
| -------- | -------- | -------- |
| N/A | string | When&nbsp;the&nbsp;type&nbsp;in&nbsp;the&nbsp;header&nbsp;returned&nbsp;by&nbsp;the&nbsp;server&nbsp;is&nbsp;**text/\***,&nbsp;**application/json**,&nbsp;**application/javascript**,&nbsp;or&nbsp;**application/xml**,&nbsp;the&nbsp;value&nbsp;is&nbsp;the&nbsp;text&nbsp;content. |
| text | string | Text&nbsp;content. |
| json | Object | A&nbsp;JSON&nbsp;object. |
**Example**
```
export default {
data: {
responseData: 'NA',
url: "test_url",
},
fetch: function () {
var that = this;
fetch.fetch({
url: that.url,
success: function(response) {
console.info("fetch success");
that.responseData = JSON.stringify(response);
},
fail: function() {
console.info("fetch fail");
}
});
}
}
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> HTTPS is supported by default. To support HTTP, you need to add **"network"** to the **config.json** file, and set the attribute **"cleartextTraffic"** to **true**.
>
> ```
> {
> "deviceConfig": {
> "default": {
> "network": {
> "cleartextTraffic": true
> }
> ...
> }
> }
> ...
> }
> ```
\ No newline at end of file
# Geographic Location
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.geolocation`](js-apis-geolocation.md) instead.
>
> - 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 geolocation from '@system.geolocation';
```
## Required Permissions
ohos.permission.LOCATION
## geolocation.getLocation
getLocation(Object): void
Obtains the geographic location.
**System capability**: SystemCapability.Location.Location.Lite
**Parameters**
| Parameter | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| timeout | number | No | Timeout&nbsp;duration,&nbsp;in&nbsp;milliseconds.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**30000**.<br/>The&nbsp;timeout&nbsp;duration&nbsp;is&nbsp;necessary&nbsp;in&nbsp;case&nbsp;the&nbsp;request&nbsp;to&nbsp;obtain&nbsp;the&nbsp;geographic&nbsp;location&nbsp;is&nbsp;rejected&nbsp;for&nbsp;the&nbsp;lack&nbsp;of&nbsp;the&nbsp;required&nbsp;permission,&nbsp;weak&nbsp;positioning&nbsp;signal,&nbsp;or&nbsp;incorrect&nbsp;location&nbsp;settings.&nbsp;After&nbsp;the&nbsp;timeout&nbsp;duration&nbsp;expires,&nbsp;the&nbsp;fail&nbsp;function&nbsp;will&nbsp;be&nbsp;called.<br/>The&nbsp;value&nbsp;is&nbsp;a&nbsp;32-digit&nbsp;positive&nbsp;integer.&nbsp;If&nbsp;the&nbsp;value&nbsp;set&nbsp;is&nbsp;less&nbsp;than&nbsp;or&nbsp;equal&nbsp;to&nbsp;**0**,&nbsp;the&nbsp;default&nbsp;value&nbsp;will&nbsp;be&nbsp;used. |
| coordType | string | No | Coordinate&nbsp;system&nbsp;type.&nbsp;Available&nbsp;types&nbsp;can&nbsp;be&nbsp;obtained&nbsp;by&nbsp;**getSupportedCoordTypes**.&nbsp;The&nbsp;default&nbsp;type&nbsp;is&nbsp;**wgs84**. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete |
The following values will be returned when the operation is successful.
| Parameter | Type | Description |
| -------- | -------- | -------- |
| longitude | number | Longitude |
| latitude | number | Latitude |
| altitude | number | Altitude |
| accuracy | number | Location&nbsp;accuracy |
| time | number | Time&nbsp;when&nbsp;the&nbsp;location&nbsp;is&nbsp;obtained |
One of the following error codes will be returned if the operation fails.
| Error&nbsp;Code | Description |
| -------- | -------- |
| 601 | Failed&nbsp;to&nbsp;obtain&nbsp;the&nbsp;required&nbsp;permission&nbsp;because&nbsp;the&nbsp;user&nbsp;rejected&nbsp;the&nbsp;request. |
| 602 | Permission&nbsp;not&nbsp;declared. |
| 800 | Operation&nbsp;times&nbsp;out&nbsp;due&nbsp;to&nbsp;a&nbsp;poor&nbsp;network&nbsp;condition&nbsp;or&nbsp;unavailable&nbsp;GPS. |
| 801 | System&nbsp;location&nbsp;disabled. |
| 802 | The&nbsp;method&nbsp;is&nbsp;called&nbsp;again&nbsp;while&nbsp;the&nbsp;previous&nbsp;execution&nbsp;result&nbsp;is&nbsp;not&nbsp;returned&nbsp;yet. |
**Example**
```
export default {
getLocation() {
geolocation.getLocation({
success: function(data) {
console.log('success get location data. latitude:' + data.latitude);
},
fail: function(data, code) {
console.log('fail to get location. code:' + code + ', data:' + data);
},
});
},
}
```
## geolocation.getLocationType
getLocationType(Object): void
Obtains the supported location types.
**System capability**: SystemCapability.Location.Location.Lite
**Parameters**
| Parameter | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete |
The following values will be returned when the operation is successful.
| Parameter | Type | Description |
| -------- | -------- | -------- |
| types | Array&lt;string&gt; | Available&nbsp;location&nbsp;types,&nbsp;['gps',&nbsp;'network'] |
**Example**
```
export default {
getLocationType() {
geolocation.getLocationType({
success: function(data) {
console.log('success get location type:' + data.types[0]);
},
fail: function(data, code) {
console.log('fail to get location. code:' + code + ', data:' + data);
},
});
},
}
```
## geolocation.subscribe
subscribe(Object): void
Listens to the geographical location. If this method is called multiple times, the last call takes effect.
**System capability**: SystemCapability.Location.Location.Lite
**Parameters**
| Parameter | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| coordType | string | No | Coordinate&nbsp;system&nbsp;type.&nbsp;Available&nbsp;types&nbsp;can&nbsp;be&nbsp;obtained&nbsp;by&nbsp;**getSupportedCoordTypes**.&nbsp;The&nbsp;default&nbsp;type&nbsp;is&nbsp;**wgs84**. |
| success | Function | Yes | Called&nbsp;when&nbsp;the&nbsp;geographical&nbsp;location&nbsp;changes |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;listening&nbsp;fails |
The following values will be returned when the network type is obtained.
| Parameter | Type | Description |
| -------- | -------- | -------- |
| longitude | number | Longitude |
| latitude | number | Latitude |
| altitude | number | Altitude |
| accuracy | number | Location&nbsp;accuracy |
| time | number | Time&nbsp;when&nbsp;the&nbsp;location&nbsp;is&nbsp;obtained |
One of the following error codes will be returned if the operation fails.
| Error&nbsp;Code | Description |
| -------- | -------- |
| 601 | Failed&nbsp;to&nbsp;obtain&nbsp;the&nbsp;required&nbsp;permission&nbsp;because&nbsp;the&nbsp;user&nbsp;rejected&nbsp;the&nbsp;request. |
| 602 | Permission&nbsp;not&nbsp;declared. |
| 801 | System&nbsp;location&nbsp;disabled. |
**Example**
```
export default {
subscribe() {
geolocation.subscribe({
success: function(data) {
console.log('get location. latitude:' + data.latitude);
},
fail: function(data, code) {
console.log('fail to get location. code:' + code + ', data:' + data);
},
});
},
}
```
## geolocation.unsubscribe
unsubscribe(): void
Cancels listening to the geographical location.
**System capability**: SystemCapability.Location.Location.Lite
**Example**
```
export default {
unsubscribe() {
geolocation.unsubscribe();
},
}
```
## geolocation.getSupportedCoordTypes
getSupportedCoordTypes(): Array&lt;string&gt;
Obtains coordinate system types supported by the device.
**System capability**: SystemCapability.Location.Location.Lite
**Return Value**
| Type | Non-Null | Description |
| -------- | -------- | -------- |
| Array&lt;string&gt; | Yes | Coordinate&nbsp;system&nbsp;types,&nbsp;for&nbsp;example,&nbsp;**[wgs84,&nbsp;gcj02]**. |
**Example**
```
export default {
getSupportedCoordTypes() {
var types = geolocation.getSupportedCoordTypes();
},
}
```
\ No newline at end of file
# Network State
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.telephony.observer`](js-apis-observer.md) instead.
>
> - 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 network from '@system.network';
```
## Required Permissions
ohos.permission.GET_WIFI_INFO
ohos.permission.GET_NETWORK_INFO
## network.getType
getType(Object): void
Obtains the network type.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete |
The following value will be returned when the multimedia volume is obtained.
| Parameter | Type | Description |
| -------- | -------- | -------- |
| metered | boolean | Whether&nbsp;the&nbsp;billing&nbsp;is&nbsp;based&nbsp;on&nbsp;the&nbsp;data&nbsp;volume. |
| type | string | Network&nbsp;type.&nbsp;The&nbsp;value&nbsp;can&nbsp;be&nbsp;**2G**,&nbsp;**3G**,&nbsp;**4G**,&nbsp;**5G**,&nbsp;**WiFi**,&nbsp;or&nbsp;**none**. |
One of the following error codes will be returned if the operation fails.
| Error&nbsp;Code | Description |
| -------- | -------- |
| 602 | The&nbsp;current&nbsp;permission&nbsp;is&nbsp;not&nbsp;declared. |
**Example**
```
export default {
getType() {
network.getType({
success: function(data) {
console.log('success get network type:' + data.type);
},
fail: function(data, code) {
console.log('fail to get network type code:' + code + ', data:' + data);
},
});
},
}
```
## network.subscribe
subscribe(Object): void
Listens to the network connection state. If this method is called multiple times, the last call takes effect.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;network&nbsp;connection&nbsp;state&nbsp;changes |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;multimedia&nbsp;volume&nbsp;fails&nbsp;to&nbsp;be&nbsp;obtained. |
The following value will be returned when the multimedia volume is obtained.
| Parameter | Type | Description |
| -------- | -------- | -------- |
| metered | boolean | Whether&nbsp;the&nbsp;billing&nbsp;is&nbsp;based&nbsp;on&nbsp;the&nbsp;data&nbsp;volume. |
| type | string | Network&nbsp;type.&nbsp;The&nbsp;value&nbsp;can&nbsp;be&nbsp;**2G**,&nbsp;**3G**,&nbsp;**4G**,&nbsp;**5G**,&nbsp;**WiFi**,&nbsp;or&nbsp;**none**. |
One of the following error codes will be returned if the listening fails.
| Error&nbsp;Code | Description |
| -------- | -------- |
| 602 | The&nbsp;current&nbsp;permission&nbsp;is&nbsp;not&nbsp;declared. |
| 200 | The&nbsp;subscription&nbsp;fails. |
**Example**
```
export default {
subscribe() {
network.subscribe({
success: function(data) {
console.log('network type change type:' + data.type);
},
fail: function(data, code) {
console.log('fail to subscribe network, code:' + code + ', data:' + data);
},
});
},
}
```
## network.unsubscribe
unsubscribe(): void
Cancels listening to the network connection state.
**System capability**: SystemCapability.Communication.NetManager.Core
**Example**
```
export default {
unsubscribe() {
network.unsubscribe();
},
}
```
\ No newline at end of file
# Application Management
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
>
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.bundle`](js-apis-Bundle.md) instead.
>
> - 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 pkg from '@system.package';
```
## package.hasInstalled
hasInstalled(Object): void
Checks whether an application exists, or whether a native application has been installed.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework
**Parameter**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes | Application&nbsp;bundle&nbsp;name |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;check&nbsp;result&nbsp;is&nbsp;obtained |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;check&nbsp;result&nbsp;fails&nbsp;to&nbsp;be&nbsp;obtained |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete |
The following value will be returned when the check result is obtained.
| Name | Type | Description |
| -------- | -------- | -------- |
| result | boolean | Whether&nbsp;the&nbsp;application&nbsp;exists,&nbsp;or&nbsp;whether&nbsp;the&nbsp;native&nbsp;application&nbsp;has&nbsp;been&nbsp;installed |
**Example**
```
export default {
hasInstalled() {
pkg.hasInstalled({
bundleName: 'com.example.bundlename',
success: function(data) {
console.log('package has installed: ' + data);
},
fail: function(data, code) {
console.log('query package fail, code: ' + code + ', data: ' + data);
},
});
},
}
```
\ No newline at end of file
# Uploading and Downloading
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.request`](js-apis-request.md) instead.
>
> - The initial APIs of this module are supported since API version 4. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import request from '@system.request';
```
## Required Permissions
ohos.permission.INTERNET.
## request.upload
upload(Object): void
Uploads files.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| url | string | Yes | URL&nbsp;of&nbsp;the&nbsp;upload&nbsp;server. |
| header | Object | No | Request&nbsp;header. |
| method | string | No | Request&nbsp;methods&nbsp;available:&nbsp;**POST**&nbsp;and&nbsp;**PUT**.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**POST**. |
| files | Array&lt;File&gt; | Yes | List&nbsp;of&nbsp;files&nbsp;to&nbsp;upload,&nbsp;which&nbsp;is&nbsp;submitted&nbsp;through&nbsp;**multipart/form-data**. |
| data | Array&lt;RequestData&gt; | No | Form&nbsp;data&nbsp;in&nbsp;the&nbsp;request&nbsp;body. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;download&nbsp;task&nbsp;is&nbsp;complete. |
| fail | Function | No | Called&nbsp;when&nbsp;downloading&nbsp;fails&nbsp;or&nbsp;the&nbsp;task&nbsp;does&nbsp;not&nbsp;exist. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Table 1** File
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| filename | string | No | File&nbsp;name&nbsp;in&nbsp;the&nbsp;header&nbsp;when&nbsp;**multipart**&nbsp;is&nbsp;used. |
| name | string | No | Name&nbsp;of&nbsp;a&nbsp;form&nbsp;item&nbsp;when&nbsp;**multipart**&nbsp;is&nbsp;used.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**file**. |
| uri | string | Yes | Local&nbsp;storage&nbsp;path&nbsp;of&nbsp;a&nbsp;file. |
| type | string | No | Type&nbsp;of&nbsp;the&nbsp;file&nbsp;content.&nbsp;By&nbsp;default,&nbsp;the&nbsp;type&nbsp;is&nbsp;obtained&nbsp;based&nbsp;on&nbsp;the&nbsp;suffix&nbsp;of&nbsp;the&nbsp;file&nbsp;name&nbsp;or&nbsp;URI. |
**Table 2** RequestData
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Name&nbsp;of&nbsp;the&nbsp;form&nbsp;element |
| value | string | Yes | Value&nbsp;of&nbsp;the&nbsp;form&nbsp;element |
The following values will be returned when the files are successfully uploaded.
| Name | Type | Description |
| -------- | -------- | -------- |
| code | number | HTTP&nbsp;status&nbsp;code&nbsp;returned&nbsp;by&nbsp;the&nbsp;server. |
| data | string | Content&nbsp;returned&nbsp;by&nbsp;the&nbsp;server.&nbsp;The&nbsp;value&nbsp;type&nbsp;is&nbsp;determined&nbsp;by&nbsp;the&nbsp;type&nbsp;in&nbsp;the&nbsp;returned&nbsp;headers. |
| headers | Object | Headers&nbsp;returned&nbsp;by&nbsp;the&nbsp;server. |
**Example**
```
export default {
upLoad() {
request.upload({
url: 'http://www.path.com',
files: [
{
uri: 'internal://cache/path/to/file.txt',
name: 'file',
filename: 'file.txt',
},
],
data:[
{
name: 'name1',
value: 'value',
},
],
success: function(data) {
console.log('upload success, code:' + data.code);
},
fail: function() {
console.log('upload fail');
},
});
}
}
```
## request.download
download(Object): void
Downloads files.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| url | string | Yes | Resource&nbsp;URL. |
| header | Object | No | Request&nbsp;header. |
| description | string | No | Download&nbsp;description.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;the&nbsp;file&nbsp;name. |
| filename | string | No | Name&nbsp;of&nbsp;the&nbsp;file&nbsp;to&nbsp;download.&nbsp;The&nbsp;value&nbsp;is&nbsp;obtained&nbsp;from&nbsp;the&nbsp;current&nbsp;request&nbsp;or&nbsp;resource&nbsp;URL&nbsp;by&nbsp;default. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;download&nbsp;task&nbsp;is&nbsp;complete. |
| fail | Function | No | Called&nbsp;when&nbsp;downloading&nbsp;fails&nbsp;or&nbsp;the&nbsp;task&nbsp;does&nbsp;not&nbsp;exist. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
Return values of the **success** callback
| Name | Type | Description |
| -------- | -------- | -------- |
| token | string | Download&nbsp;token,&nbsp;which&nbsp;is&nbsp;used&nbsp;to&nbsp;obtain&nbsp;the&nbsp;download&nbsp;status. |
One of the following error codes will be returned if the operation fails.
| Error&nbsp;Code | Description |
| -------- | -------- |
| 400 | Download&nbsp;task&nbsp;failed |
**Example**
```
export default {
downLoad() {
request.download({
url: 'http://www.path.com',
success: function(data) {
console.log('call success callback success: ' + data.token);
},
fail: function(data, code) {
console.log('handling fail');
},
});
}
}
```
## request.onDownloadComplete
onDownloadComplete(Object): void
Listens to download task status.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| token | string | Yes | Token&nbsp;of&nbsp;the&nbsp;result&nbsp;returned&nbsp;by&nbsp;the&nbsp;download&nbsp;method |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;download&nbsp;task&nbsp;is&nbsp;complete. |
| fail | Function | No | Called&nbsp;when&nbsp;downloading&nbsp;fails&nbsp;or&nbsp;the&nbsp;task&nbsp;does&nbsp;not&nbsp;exist. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
Return values of the **success** callback
| Name | Type | Description |
| -------- | -------- | -------- |
| uri | string | URI&nbsp;of&nbsp;the&nbsp;download&nbsp;file |
One of the following error codes will be returned if the listening fails.
| Error&nbsp;Code | Description |
| -------- | -------- |
| 400 | Download&nbsp;task&nbsp;failed |
| 401 | Download&nbsp;task&nbsp;not&nbsp;exist |
**Example**
```
export default {
onDownloadComplete() {
request.onDownloadComplete({
token: 'token-index',
success: function(data) {
console.log('download success, uri:' + data.uri);
},
fail: function(data, code) {
console.log('download fail');
},
});
}
}
```
\ No newline at end of file
# Data Storage
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.data.storage`](js-apis-data-storage.md) instead.
>
> - 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 storage from '@system.storage';
```
## storage.get
get(Object): void
Reads the stored content.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| key | string | Yes | Content&nbsp;index. |
| default | string | No | Default&nbsp;value&nbsp;returned&nbsp;when&nbsp;the&nbsp;**key**&nbsp;does&nbsp;not&nbsp;exist. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;stored&nbsp;content&nbsp;is&nbsp;successfully&nbsp;read. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;stored&nbsp;content&nbsp;fails&nbsp;to&nbsp;be&nbsp;read. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example**
```
export default {
storageGet() {
storage.get({
key: 'storage_key',
success: function(data) {
console.log('call storage.get success: ' + data);
},
fail: function(data, code) {
console.log('call storage.get fail, code: ' + code + ', data: ' + data);
},
complete: function() {
console.log('call complete');
},
});
}
}
```
## storage.set
set(Object): void
Modifies the stored content.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| key | string | Yes | Index&nbsp;of&nbsp;the&nbsp;stored&nbsp;content&nbsp;to&nbsp;be&nbsp;modified. |
| value | string | No | Target&nbsp;storage&nbsp;content.&nbsp;The&nbsp;maximum&nbsp;number&nbsp;of&nbsp;characters&nbsp;allowed&nbsp;is&nbsp;128. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;stored&nbsp;content&nbsp;is&nbsp;modified&nbsp;successfully. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;stored&nbsp;content&nbsp;fails&nbsp;to&nbsp;be&nbsp;modified. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example**
```
export default {
storageSet() {
storage.set({
key: 'storage_key',
value: 'storage value',
success: function() {
console.log('call storage.set success.');
},
fail: function(data, code) {
console.log('call storage.set fail, code: ' + code + ', data: ' + data);
},
});
}
}
```
## storage.clear
clear(Object): void
Clears the stored content.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;stored&nbsp;content&nbsp;is&nbsp;cleared&nbsp;successfully |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;stored&nbsp;content&nbsp;fails&nbsp;to&nbsp;be&nbsp;cleared |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete |
**Example**
```
export default {
storageClear() {
storage.clear({
success: function() {
console.log('call storage.clear success.');
},
fail: function(data, code) {
console.log('call storage.clear fail, code: ' + code + ', data: ' + data);
},
});
}
}
```
## storage.delete
delete(Object): void
Deletes the stored content.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| key | string | Yes | Content&nbsp;index. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;stored&nbsp;content&nbsp;is&nbsp;deleted&nbsp;successfully. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;stored&nbsp;content&nbsp;fails&nbsp;to&nbsp;be&nbsp;deleted. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example**
```
export default {
storageDelete() {
storage.delete({
key: 'Storage1',
success: function() {
console.log('call storage.delete success.');
},
fail: function(data, code) {
console.log('call storage.delete fail, code: ' + code + ', data: ' + data);
},
});
}
}
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册