react-native-wifi-manager-1app
Device Information for react-native
Installation
First you need to install react-native-wifi-manager-1app:
npm install react-native-wifi-manager-1app --save
- In
android/setting.gradle
...
include ':WifiManager', ':app'
project(':WifiManager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wifi-manager-1app/android')
- In
android/app/build.gradle
...
dependencies {
...
compile project(':WifiManager')
}
- register module (in MainActivity.java)
On newer versions of React Native (0.18+):
import com.skierkowski.WifiManager.*;
public class MainActivity extends ReactActivity {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new WifiManager(),
new MainReactPackage());
}
}
On older versions of React Native:
import com.skierkowski.WifiManager.*;
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 WifiManager())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null);
setContentView(mReactRootView);
}
......
}
Example
Load module
var WifiManager = require('react-native-wifi-manager-1app');
List available networks (list)
loadWifiListData: function() {
WifiManager.list(
(wifiArray) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(wifiArray),
});
},
(msg) => {
console.log(msg);
},
);
},
Connect to a new network (status)
WifiManager.connect(ssid,password);
Get status of connection (status)
checkConnectionStatus: function() {
WifiManager.status((status) => {
if (status == 'CONNECTED') {
this.navigateToActivation();
}
});
},