HomeDocs
Skip to main content

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

PropertyTypeDescription
networkTypestringThe current network environment.
weakNetbooleanWhether it is a weak network.
successstringIndicates whether the operation was successful.

Possible Values for networkType

ValueDescription
wifiWi-Fi network
2g2G network
3g3G network
4g4G network
5g5G network
unknownUncommon network types on Android
noneNo network

Example Code

// pages/index/index.js

Page({
onNetworkStatusChange() {
dlt.onNetworkStatusChange(function (res) {
console.log(res.networkType);
console.log(res.weakNet);
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.