my.getNetworkType

Get the current network status.

Sample code

copy
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:

  • UNKNOWN: The network type is unknown. For Android,If the client's permission to obtain phone information is set to "ask" or "deny", the return value is UNKNOWN.
  • NOTREACHABLE: The network is not available.
  • WWANWireless Wide Area Network
  • WIFI: Wifi nework
  • 2G2G network
  • 3G3G network
  • 4G4G network
  • 5G5G network

signalStrength

Number

Indicates the signal strength in "dbm" unit. This parameter is used only when the networkType is WIFI.

Note: This parameter is returned only for Android.

hasSystemProxy

Boolean

Indicates whether using the network proxy.