react-native-android-wifi
A react-native module for viewing and connecting to Wifi networks on Android devices.

Installation
Add it to your android project
npm install react-native-android-wifi --save
Install the native dependencies
Use react-native link to install native dependencies automatically:
react-native link react-native-android-wifi
or do it manually as described here.
Example usage
import wifi from 'react-native-android-wifi';
Permissions: Starting with Android API 25, apps must be granted the ACCESS_COARSE_LOCATION (or ACCESS_FINE_LOCATION) permission in order to obtain results.
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
'title': 'Wifi networks',
'message': 'We need your permission in order to find wifi networks'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Thank you for your permission! :)");
} else {
console.log("You will not able to retrieve wifi available networks list");
}
} catch (err) {
console.warn(err)
}
Wifi connectivity status:
wifi.isEnabled((isEnabled) => {
if (isEnabled) {
console.log("wifi service enabled");
} else {
console.log("wifi service is disabled");
}
});
Enable/Disable wifi service:
wifi.setEnabled(true);
Sign device into a specific network:
This method doesn't have a callback when connection succeeded, check this issue.
Added support for 'WPA2 PSK' wifi security mode and handling SSID for Lollipop and Kitkat.
wifi.findAndConnect(ssid, password, (found) => {
if (found) {
console.log("wifi is in range");
} else {
console.log("wifi is not in range");
}
});
Disconnect from current wifi network
wifi.disconnect();
Get current SSID
wifi.getSSID((ssid) => {
console.log(ssid);
});
Get current BSSID
wifi.getBSSID((bssid) => {
console.log(bssid);
});
Get all wifi networks in range
wifi.loadWifiList((wifiStringList) => {
var wifiArray = JSON.parse(wifiStringList);
console.log(wifiArray);
},
(error) => {
console.log(error);
}
);
connectionStatus returns true or false depending on whether device is connected to wifi
wifi.connectionStatus((isConnected) => {
if (isConnected) {
console.log("is connected");
} else {
console.log("is not connected");
}
});
Get connected wifi signal strength
wifi.getCurrentSignalStrength((level) => {
console.log(level);
});
Get connected wifi frequency
wifi.getFrequency((frequency) => {
console.log(frequency);
})
Get current IP
wifi.getIP((ip) => {
console.log(ip);
});
Get DHCP Server Adress
wifi.getDhcpServerAddress((ip) => {
console.log(ip);
});
Remove/Forget the Wifi network from mobile by SSID, returns boolean
This method will remove the wifi network as per the passed SSID from the device list.
wifi.isRemoveWifiNetwork(ssid, (isRemoved) => {
console.log("Forgetting the wifi device - " + ssid);
});
Starts native Android wifi network scanning and returns list
Hard refresh the Android wifi scan, implemented using BroadcastReceiver
to ensure that it automatically detects new wifi connections available.
wifi.reScanAndLoadWifiList((wifiStringList) => {
var wifiArray = JSON.parse(wifiStringList);
console.log('Detected wifi networks - ',wifiArray);
},(error)=>{
console.log(error);
});
Method to force wifi usage. Android by default sends all requests via mobile data if the connected wifi has no internet connection.
wifi.forceWifiUsage(true);
Method to get connection status of a forced network (because it takes some time to be set up).
wifi.connectionStatusOfBoundNetwork((isBound) => {
if (isBound) {
console.log('Network is bound');
} else {
console.log('Network isn\'t bound');
}
});
Add a hidden wifi network and connect to it
wifi.connectToHiddenNetwork(ssid, password, (networkAdded) => {});