This interface provides information about network connectivity.
enum DeviceNetworkType {
Unknown,
None,
Wifi,
Mobile2G,
Mobile3G,
Mobile4G
}
// Returns a promise that specifies whether the device currently
// has network connectivity
isConnected(): SyncTasks.Promise<boolean>;
// Returns the type of network
getType(): SyncTasks.Promise<DeviceNetworkType>;
// Triggered when the connectivity changes
connectivityChangedEvent: SubscribableEvent<(isConnected: boolean) => void>;
private isConnected: boolean;
constructor() {
// Query the initial connectivity state.
this.isConnected = false;
RXNetInfo.isConnected().then(isConnected => {
this.isConnected = isConnected;
});
RXNetInfo.connectivityChangedEvent.subscribe(isConnected => {
// Update the connectivity state.
this.isConnected = isConnected;
});
}
On Android, the following permission must be added to make use of the network interfaces.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />