expo-network
@amazon-devices/expo-network
provides useful information about the device's network such as its IP address, MAC address, and airplane mode status.
Installation
- Add the JavaScript library dependency in the
package.json
file.dependencies: { ... "@amazon-devices/expo-network": "~2.0.0", }
- Reinstall dependencies using
npm install
command.
Examples
To test network features, you need to connect to the WiFi on your device shell. Replace NETWORK
and PASSWORD
with your credentials.
> ace mw wifi add_network ssid=$NETWORK psk=$PASSWORD
> ace mw wifi connect $NETWORK
import * as Network from '@amazon-devices/expo-network';
import React, {useEffect, useState} from 'react';
import {StyleSheet, Text, View} from 'react-native';
export const App = () => {
const [networkState, setNetworkState] = useState<Network.NetworkState>();
const [ipAddress, setIpAddress] = useState<string>();
const [airplaneModeEnabled, setAirplaneModeEnabled] = useState<boolean>();
useEffect(() => {
(async () => {
setNetworkState(await Network.getNetworkStateAsync());
setIpAddress(await Network.getIpAddressAsync());
setAirplaneModeEnabled(await Network.isAirplaneModeEnabledAsync());
})();
}, []);
return (
<View style={styles.container}>
<Text style={styles.text}>
getNetworkStateAsync().type: {networkState?.type}
</Text>
<Text style={styles.text}>
getNetworkStateAsync().isConnected: {String(networkState?.isConnected)}
</Text>
<Text style={styles.text}>
getNetworkStateAsync().isInternetReachable:{' '}
{String(networkState?.isInternetReachable)}
</Text>
<Text style={styles.text}>getIpAddressAsync(): {ipAddress}</Text>
<Text style={styles.text}>
isAirplaneModeEnabledAsync(): {String(airplaneModeEnabled)}
</Text>
</View>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1,
},
text: {
color: 'black',
fontSize: 32,
},
});
API reference
Check out the dedicated documentation page for info about this library, API reference and more: Official Expo documentation for expo-network.
Methods
Name | Type | Description |
---|---|---|
Network.getIpAddressAsync() |
Promise<string> |
Gets the device's current IPv4 address. Returns 0.0.0.0 if the IP address could not be retrieved. |
Network.getNetworkStateAsync() |
Promise<NetworkState> |
Gets the device's current network connection state. |
Network.isAirplaneModeEnabledAsync() |
Promise<boolean> |
Tells if the device is in airplane mode. On Kelper always return false . |
Implementation details
Network.isAirplaneModeEnabledAsync()
- always returns falseNetwork.getNetworkStateAsync()
-isInternetReachable
field is always missingNetwork.getNetworkStateAsync()
-type
field can only be eitherNONE
orWIFI
Test on the simulator
You can test the network connection on the Vega Virtual Device by running the following commands.
vda shell
ace mw wifi_cli add_network ssid=test psk=test_password
ace mw wifi_cli connect test
Supported versions
Package Version | Based On | @amazon-devices/react-native-kepler version |
---|---|---|
2.0.x | 5.7.0 | 2.0.x |
Additional resources
For information on additional libraries, see Supported Third-Party Libraries and Services.
Last updated: Sep 30, 2025