my.getNetworkType
Get the current network status.
Sample code
Page({
data: {
hasNetworkType: false,
networkType:''
},
getNetworkType() {
my.getNetworkType({
success: (res) => {
this.setData({
hasNetworkType: true,
networkType: res.networkType
})
},
fail: (error) => {
console.log(error)
},
})
},
clear() {
this.setData({
hasNetworkType: false,
networkType: ''
})
},
});
Parameters
Property | Type | Required | Description |
success | Function | No | The callback function that is called upon successful call. |
fail | Function | No | The callback function that is called upon failed call. |
complete | Function | No | The callback function that is called upon call completion (to be executed upon either call success or failure). |
Success callback function
The incoming parameter is of the Object type with the following attributes:
Property | Type | Description |
networkAvailable | Boolean | Indicates whether the network is available. |
networkType | String | Indicates the network type. Valid value:
|
signalStrength | Number | Indicates the signal strength in "dbm" unit. This parameter is used only when the Note: This parameter is returned only for Android. |
hasSystemProxy | Boolean | Indicates whether using the network proxy. |