Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skierkowski/react-native-wifi-manager
A WiFi connection manager for React Native
https://github.com/skierkowski/react-native-wifi-manager
Last synced: 10 days ago
JSON representation
A WiFi connection manager for React Native
- Host: GitHub
- URL: https://github.com/skierkowski/react-native-wifi-manager
- Owner: skierkowski
- License: mit
- Created: 2016-01-19T01:13:37.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-19T04:16:36.000Z (almost 9 years ago)
- Last Synced: 2024-12-24T06:57:36.843Z (18 days ago)
- Language: Java
- Size: 15.6 KB
- Stars: 35
- Watchers: 4
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-react-native - react-native-wifi-manager ★29 - Wifi Connection Manager for React Native on Android (Components / System)
- awesome-react-native - react-native-wifi-manager ★29 - Wifi Connection Manager for React Native on Android (Components / System)
- awesome-react-native - react-native-wifi-manager ★29 - Wifi Connection Manager for React Native on Android (Components / System)
- awesome-react-native-ui - react-native-wifi-manager ★14 - Wifi Connection Manager for React Native on Android (Components / System)
- awesome-react-native - react-native-wifi-manager ★29 - Wifi Connection Manager for React Native on Android (Components / System)
README
## WiFi Manager for React Native (react-native-wifi-manager)
[![npm version](https://badge.fury.io/js/react-native-wifi-manager.png)](http://badge.fury.io/js/react-native-wifi-manager)List, connect and get the status of the WiFi connection on the device.
## Installation
First you need to install react-native-wifi-manager:
```javascript
npm install react-native-wifi-manager --save
```* In `android/app/src/main/AndroidManifest.xml` add these permissions inside ``.
```xml
```
* In `android/setting.gradle`
```gradle
...
include ':WifiManager', ':app'
project(':WifiManager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wifi-manager/android')
```* In `android/app/build.gradle`
```gradle
...
dependencies {
...
compile project(':WifiManager')
}
```* register module (in MainActivity.java)
On newer versions of React Native (0.18+):
```java
import com.skierkowski.WifiManager.*; // <--- importpublic class MainActivity extends ReactActivity {
......
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
@Override
protected List getPackages() {
return Arrays.asList(
new WifiManager(), // <------ add here
new MainReactPackage());
}
}
```On older versions of React Native:
```java
import com.skierkowski.WifiManager.*; // <--- importpublic 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 WifiManager()) // <------ add here
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null);
setContentView(mReactRootView);
}......
}
```## Example
### Load module
```javascript
var WifiManager = require('react-native-wifi-manager');
```### List available networks (list)
```javascript
loadWifiListData: function() {
WifiManager.list(
(wifiArray) => {
this.setState({
// wifiArray is an array of strings, each string being the SSID
dataSource: this.state.dataSource.cloneWithRows(wifiArray),
});
},
(msg) => {
console.log(msg);
},
);
},
```### Connect to a new network (connect)
```javascript
// Attempts to connect to the network specified. This is an async call. Listen to connectionStatus for status
WifiManager.connect(ssid,password);
```### Get status of connection (status)
```javascript
checkConnectionStatus: function() {
// Possible States: 'CONNECTED', 'CONNECTING', 'DISCONNECTED', 'DISCONNECTING', 'SUSPENDED', 'UNKOWN'
// from: http://developer.android.com/reference/android/net/NetworkInfo.State.html
WifiManager.status((status) => {
if (status == 'CONNECTED') {
this.navigateToActivation();
}
});
},
```