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
;
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 if granted === PermissionsAndroidRESULTSGRANTED console; else console; catch err console
Wifi connectivity status:
wifi;
Enable/Disable wifi service:
//Set TRUE to enable and FALSE to disable; wifi;
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.
//found returns true if ssid is in the rangewifi;
Disconnect from current wifi network
wifi;
Get current SSID
wifi;
Get current BSSID
wifi;
Get all wifi networks in range
/*wifiStringList is a stringified JSONArray with the following fields for each scanned wifi{ "SSID": "The network name", "BSSID": "The address of the access point", "capabilities": "Describes the authentication, key management, and encryption schemes supported by the access point" "frequency":"The primary 20 MHz frequency (in MHz) of the channel over which the client is communicating with the access point", "level":"The detected signal level in dBm, also known as the RSSI. (Remember its a negative value)", "timestamp":"Timestamp in microseconds (since boot) when this result was last seen"}*/wifi;
connectionStatus returns true or false depending on whether device is connected to wifi
wifi;
Get connected wifi signal strength
//level is the detected signal level in dBm, also known as the RSSI. (Remember its a negative value)wifi;
Get connected wifi frequency
wifi
Get current IP
//get the current network connection IPwifi;
Get DHCP Server Adress
//get the DHCP server IPwifi;
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;
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;
Method to force wifi usage. Android by default sends all requests via mobile data if the connected wifi has no internet connection.
//Set true/false to enable/disable forceWifiUsage.//Is important to enable only when communicating with the device via wifi//and remember to disable it when disconnecting from device.wifi;