Giter Club home page Giter Club logo

react-native-android-wifi's Introduction

react-native-android-wifi

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

example app

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

or do it manually as described here.

Example usage

var wifi = require('react-native-android-wifi')

Wifi connectivity status:

wifi.isEnabled((isEnabled)=>{
  if (isEnabled){
    console.log("wifi service enabled");
  }else{
    console.log("wifi service is disabled");
  }
});

Enable/Disable wifi service:

//Set TRUE to enable and FALSE to disable; 
wifi.setEnabled(true);

Sign device into a specific network:

This method doesn't have a callback when connection succeeded, check this issue.

//found returns true if ssid is in the range
wifi.findAndConnect(ssid, password, (found) => {
  if (found) {
    console.log("wifi is in range");
  }else{
    console.log("wifi is not in range");
  }
});

Disconnect 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

/*
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.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

//level is the detected signal level in dBm, also known as the RSSI. (Remember its a negative value)
wifi.getCurrentSignalStrength((level)=>{
  console.log(level);
});

Get current IP

//get the current network connection IP
wifi.getIP((ip)=>{
  console.log(ip);
});

Remove/Forget the Wifi network from mobile by SSID, returns boolean

wifi.isRemoveWifiNetwork(ssid, (isRemoved) => {
  console.log("Forgetting the wifi device - " + ssid);
});

Starts native Android wifi network scanning and returns list

wifi.reScanAndLoadWifiList((wifiStringList) => {
  var wifiArray = JSON.parse(wifiStringList);
  console.log('Detected wifi networks - ',wifiArray);
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.