A one day, single-track online event celebrating the future of cross-platform app development

DocsプラグインCLI
pwaiosandroid

Network

Network API は、ネットワークの現在の状態を照会するとともに、ネットワークステータスの変化を監視するためのイベントを提供します。

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

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

Param Type
eventName "networkStatusChange"
listenerFunc (status: NetworkStatus) => void

Returns: PluginListenerHandle


removeAllListeners()

removeAllListeners() => void

Remove all native listeners for this plugin


Interfaces

NetworkStatus

Prop Type
connected boolean
connectionType "none" | "unknown" | "wifi" | "cellular"

PluginListenerHandle

Prop Type
remove () => void
Previous
<- Motion
Next
Permissions ->
Contribute ->