react-native-netinfo
The react-native-netinfo API allows you to access network connection information.
Installation
Follow the steps below to install react-native-netinfo
.
- Add the library dependency in your React Native for Vega application's
package.json
:"dependencies": { ... "@amazon-devices/keplerscript-netmgr-lib": "~2.0.0", ... }
- Add
com.amazon.network.service
to[wants.service]
in your React Native for Vega app'smanifest.toml
:[[wants.service]] id = "com.amazon.network.service"
- Add API permission to
[wants.privilege]
in your React Native for Vega app'smanifest.toml
:[wants] [[wants.privilege]] id="com.amazon.network.privilege.net-info"
- Reinstall dependencies using
npm install
command.
API privileges
To access full API functionality, your app needs the com.amazon.network.privilege.net-info
privilege. This privilege must be granted by the user at runtime. Without it, API responses will be limited. To manage privileges:
- Check the current privilege status using
checkPrivilege("com.amazon.network.privilege.net-info")
. - If needed, request user consent by calling
requestPrivilege()
.
For complete details, see the Security Manager API documentation.
Usage
The following code snippet shows how to query network status:
import {NetInfoStateType, fetch} from "@amazon-devices/keplerscript-netmgr-lib";
fetch().then(state => {
console.log("is connected? " + state.isConnected);
if (state.type === NetInfoStateType.wifi) {
console.log("ssid is " + state.details.ssid);
}
});
Supported Methods
API | Description |
---|---|
fetch() |
Returns cached network information. |
refresh() |
Updates network state and returns network information. |
addEventListener() |
Listens for network connection changes. |
useNetInfo() |
Gets access to the latest state from the global instance. |
fetch()
and refresh()
returns NetInfoState
to access the network connection information.
Property | Description |
---|---|
type |
NetInfoStateType.wifi if the connection is Wi-Fi. |
isConnected |
true if Wi-Fi is connected; otherwise false . |
isInternetReachable |
true if the internet is reachable; otherwise false . |
ssid in details |
The SSID of the connected access point. null or empty string if com.amazon.network.privilege.net-info privilege is denied. |
bssid in details |
The BSSID of the connected access point.null or empty string if com.amazon.network.privilege.net-info privilege is denied. |
strength in details |
The signal strength of the current Wi-Fi connection. |
ipAddress in details |
The IP address.null if com.amazon.network.privilege.net-info privilege is denied. |
subnet in details |
The subnet mask. null if com.amazon.network.privilege.net-info privilege is denied. |
frequency in details |
The center frequency. null if com.amazon.network.privilege.net-info privilege is denied. |
linkspeed in details |
The link speed in bps of the current connection. |
isConnectionExpensive in details |
true if the connection is expensive; otherwise false . |
Implementation details
Test on the simulator
You can test the network connection on the Vega Virtual Device by running the following commands.
kepler exec vda shell
ace mw wifi_cli add_network ssid=test psk=test_password
ace mw wifi_cli connect test
Supported versions
package version | @amazon-devices/react-native-kepler version |
---|---|
2.0.x | 2.0.x+rn0.72.0 |
Additional resources
For information on additonal libraries, see Supported Third-Party Libraries and Services.
Last updated: Sep 30, 2025