# Network Information network
# Interface Declaration
{ "name": "system.network" }
# Import Module
import network from '@system.network'
// or
const network = require('@system.network')
# Interface Definition
# network.getType(OBJECT)
Obtain the network type.
# Parameters:
| Parameter Name | Type | Required | Description |
|---|---|---|---|
| success | Function | No | Callback for success |
| fail | Function | No | Callback for failure, possibly due to lack of permissions |
| complete | Function | No | Callback after execution ends |
# Return Value for success:
| Parameter Name | Type | Description |
|---|---|---|
| type | String | Network type, possible values are 2g, 3g, 4g, wifi, none, 5g, bluetooth, others |
# Example:
network.getType({
success: function(data) {
console.log(`handling success: ${data.type}`)
}
})
# network.subscribe(OBJECT)
Listen for changes in network type. If called multiple times, only the last call will take effect.
# Parameters:
| Parameter Name | Type | Required | Description |
|---|---|---|---|
| callback | Function | No | Callback each time the network changes |
| fail | Function | No | Callback for failure, possibly due to lack of permissions |
# Return Value for callback:
| Parameter Name | Type | Description |
|---|---|---|
| type | String | Network type, possible values are 2g, 3g, 4g, wifi, none, 5g, bluetooth, others. Note: A network type other than none does not guarantee that the device can access the target server; a request interface must be used to make this determination. |
# Example:
network.subscribe({
callback: function(data) {
console.log('handling callback')
}
})
# network.unsubscribe()
Cancel listening for changes in network type.
# Parameters:
None
# Example:
network.unsubscribe()
# Support Details
| Device Product | Description |
|---|---|
| Xiaomi S1 Pro Sports and Health Watch | Supported |
| Xiaomi Band 8 Pro | Not Supported |
| Xiaomi Band 9 / 9 Pro | Not Supported |
| Xiaomi Watch S3 | Supported |
| Redmi Watch 4 | Not Supported |
| Xiaomi Wrist ECG Blood Pressure Monitor | Not Supported |
| Xiaomi Band 10 | Not Supported |
| Xiaomi Watch S4 | Supported |
| REDMI Watch 5 | Supported |
← File Storage Vibrator →