pwa
ios
android
electron

Network

The Network API provides events for monitoring network status changes, along with querying the current state of the network.

getStatus()
addListener('networkStatusChange')

Example

import { Plugins } from '@capacitor/core';

const { Network } = Plugins;

let handler = Network.addListener('networkStatusChange', (status) => {
  console.log("Network status changed", status);
});
// To stop listening:
// handler.remove();

// Get the current network status
let status = await Network.getStatus();

// Example output:
{
  "connected": true,
  "connectionType": "wifi"
}

Android Note

The Network API requires the following permission be added to your AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

This permission allows the app to access information about the current network, such as whether it is connected to wifi or cellular.

API

NetworkPlugin

getStatus

getStatus(): Promise<
NetworkStatus
>
Query the current network status
Returns: Promise<
NetworkStatus
>

addListener

addListener(eventName: "networkStatusChange", listenerFunc: (status:
NetworkStatus
) => void
):
PluginListenerHandle
Listen for network status change events
eventName "networkStatusChange"
listenerFunc (status:
NetworkStatus
) => void
Returns:
PluginListenerHandle

Interfaces