1.0.9 • Published 10 years ago

react-native-wifi-module v1.0.9

Weekly downloads
3
License
ISC
Repository
github
Last release
10 years ago

react-native-wifi-module (Android)

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

Installation

npm install react-native-wifi-module --save

Add it to your android project

  • In android/setting.gradle
...
include ':WifiModule', ':app'
project(':WifiModule').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wifi-module')
  • In android/app/build.gradle
...
dependencies {
    ...
    compile project(':WifiModule')
}
  • Register Module (in MainActivity.java)
import com.ccmxy.wifimanager.WifiPackage;  // <--- import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
  ......

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mReactRootView = new ReactRootView(this);

    mReactInstanceManager = ReactInstanceManager.builder()
      .setApplication(getApplication())
      .setBundleAssetName("index.android.bundle")
      .setJSMainModuleName("index.android")
      .addPackage(new MainReactPackage())
      .addPackage(new WifiPackage()) // <------ add this line
      .setUseDeveloperSupport(BuildConfig.DEBUG)
      .setInitialLifecycleState(LifecycleState.RESUMED)
      .build();

      ....
  }

  ......

}

Example usage

var wifiModule = require('react-native-wifi-module')

Toast all networks:

wifiModule.toastAllNetworks();

Sign device into a specific network:

wifiModule.findAndConnect(ssid, password);

You can put all wifi networks into a ListView like this:

wifiModule.loadWifiList((wifiString) => {
var wifiArray = wifiString.split('SSID:');
this.setState({
  dataSource: this.state.dataSource.cloneWithRows(wifiArray),
     loaded: true,
     });
 },
 (msg) => {
     console.log(msg);
   },
 );

connectionStatus returns true or false depending on whether device is connected to wifi:

wifiModule.connectionStatus((isConnected) => {
  if (isConnected) {
    //Do something
  }
},

Screenshots

  • Version of the app which implements RNSimpleAlertDialogModule by lucas ferreira

Screenshot from a version of this app which implements RNSimpleAlertDialogModule by lucas ferreira

Upon connecting

3

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago