dlt.onNetworkStatusChange
Introduction
Listen for network status change events.
Note:
Currently, only accurate changes between Wi-Fi, cellular data, and no network are supported.
There is a possibility that changes from 2G to 4G and other cellular data network states may not be detected. It is recommended that developers do not rely too much on this feature of detecting changes in cellular data network types.
Parameters
function listener The listener function for the network status change event.
Return Value
Object res
Property | Type | Description |
---|---|---|
networkType | string | The current network environment. |
weakNet | boolean | Whether it is a weak network. |
success | string | Indicates whether the operation was successful. |
Possible Values for networkType
Value | Description |
---|---|
wifi | Wi-Fi network |
2g | 2G network |
3g | 3G network |
4g | 4G network |
5g | 5G network |
unknown | Uncommon network types on Android |
none | No network |
Example Code
// pages/index/index.js
Page({
onNetworkStatusChange() {
dlt.onNetworkStatusChange(function (res) {
console.log(res.networkType);
console.log(res.weakNet);
});
},
});