├── .gitignore ├── .npmignore ├── Examples ├── Example │ ├── .babelrc │ ├── .buckconfig │ ├── .flowconfig │ ├── .gitattributes │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── android │ │ ├── app │ │ │ ├── BUCK │ │ │ ├── build.gradle │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ │ └── res │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── keystores │ │ │ ├── BUCK │ │ │ └── debug.keystore.properties │ │ └── settings.gradle │ ├── app.json │ ├── index.js │ ├── ios │ │ ├── Example-tvOS │ │ │ └── Info.plist │ │ ├── Example-tvOSTests │ │ │ └── Info.plist │ │ ├── Example.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── xcshareddata │ │ │ │ └── xcschemes │ │ │ │ ├── Example-tvOS.xcscheme │ │ │ │ └── Example.xcscheme │ │ ├── Example │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── Base.lproj │ │ │ │ └── LaunchScreen.xib │ │ │ ├── Images.xcassets │ │ │ │ ├── AppIcon.appiconset │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ ├── Info.plist │ │ │ └── main.m │ │ └── ExampleTests │ │ │ ├── ExampleTests.m │ │ │ └── Info.plist │ ├── package-lock.json │ └── package.json └── ExampleAPI25 │ ├── .babelrc │ ├── .buckconfig │ ├── .flowconfig │ ├── .gitattributes │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── android │ ├── app │ │ ├── BUCK │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── exampleapi25 │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── keystores │ │ ├── BUCK │ │ └── debug.keystore.properties │ └── settings.gradle │ ├── app.json │ ├── index.js │ ├── ios │ ├── ExampleAPI25-tvOS │ │ └── Info.plist │ ├── ExampleAPI25-tvOSTests │ │ └── Info.plist │ ├── ExampleAPI25.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ ├── ExampleAPI25-tvOS.xcscheme │ │ │ └── ExampleAPI25.xcscheme │ ├── ExampleAPI25 │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ │ └── LaunchScreen.xib │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── Info.plist │ │ └── main.m │ └── ExampleAPI25Tests │ │ ├── ExampleAPI25Tests.m │ │ └── Info.plist │ ├── package-lock.json │ └── package.json ├── LICENSE ├── README.md ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── devstepbcn │ └── wifi │ ├── AndroidWifiModule.java │ └── AndroidWifiPackage.java ├── docs ├── example-app.gif └── link-manually.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.war 8 | *.ear 9 | 10 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 11 | hs_err_pid* 12 | 13 | # OSX 14 | # 15 | .DS_Store 16 | 17 | # Xcode 18 | # 19 | build/ 20 | *.pbxuser 21 | !default.pbxuser 22 | *.mode1v3 23 | !default.mode1v3 24 | *.mode2v3 25 | !default.mode2v3 26 | *.perspectivev3 27 | !default.perspectivev3 28 | xcuserdata 29 | *.xccheckout 30 | *.moved-aside 31 | DerivedData 32 | *.hmap 33 | *.ipa 34 | *.xcuserstate 35 | project.xcworkspace 36 | android/.gradle/ 37 | # node.js 38 | # 39 | node_modules/ 40 | npm-debug.log 41 | 42 | #Example 43 | Example/node_modules/ 44 | Example/andoid/build -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Don't publish example app 2 | 3 | Example/ 4 | docs/ 5 | build/ -------------------------------------------------------------------------------- /Examples/Example/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react-native"] 3 | } 4 | -------------------------------------------------------------------------------- /Examples/Example/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /Examples/Example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | 16 | ; Ignore polyfills 17 | .*/Libraries/polyfills/.* 18 | 19 | ; Ignore metro 20 | .*/node_modules/metro/.* 21 | 22 | [include] 23 | 24 | [libs] 25 | node_modules/react-native/Libraries/react-native/react-native-interface.js 26 | node_modules/react-native/flow/ 27 | node_modules/react-native/flow-github/ 28 | 29 | [options] 30 | emoji=true 31 | 32 | module.system=haste 33 | 34 | munge_underscores=true 35 | 36 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 37 | 38 | module.file_ext=.js 39 | module.file_ext=.jsx 40 | module.file_ext=.json 41 | module.file_ext=.native.js 42 | 43 | suppress_type=$FlowIssue 44 | suppress_type=$FlowFixMe 45 | suppress_type=$FlowFixMeProps 46 | suppress_type=$FlowFixMeState 47 | 48 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 49 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 50 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 51 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 52 | 53 | [version] 54 | ^0.67.0 55 | -------------------------------------------------------------------------------- /Examples/Example/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /Examples/Example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://docs.fastlane.tools/best-practices/source-control/ 50 | 51 | */fastlane/report.xml 52 | */fastlane/Preview.html 53 | */fastlane/screenshots 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | -------------------------------------------------------------------------------- /Examples/Example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /Examples/Example/App.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { 9 | Modal, 10 | StyleSheet, 11 | Text, 12 | TextInput, 13 | TouchableHighlight, 14 | ScrollView, 15 | View, 16 | PermissionsAndroid 17 | } from 'react-native'; 18 | 19 | import wifi from 'react-native-android-wifi'; 20 | 21 | type Props = {}; 22 | export default class App extends Component { 23 | constructor(props){ 24 | super(props); 25 | this.state = { 26 | isWifiNetworkEnabled: null, 27 | ssid: null, 28 | pass: null, 29 | ssidExist: null, 30 | currentSSID: null, 31 | currentBSSID: null, 32 | wifiList: null, 33 | modalVisible: false, 34 | status:null, 35 | level: null, 36 | ip: null, 37 | }; 38 | 39 | } 40 | 41 | componentDidMount (){ 42 | console.log(wifi); 43 | this.askForUserPermissions(); 44 | } 45 | 46 | async askForUserPermissions() { 47 | try { 48 | const granted = await PermissionsAndroid.request( 49 | PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, 50 | { 51 | 'title': 'Wifi networks', 52 | 'message': 'We need your permission in order to find wifi networks' 53 | } 54 | ) 55 | if (granted === PermissionsAndroid.RESULTS.GRANTED) { 56 | console.log("Thank you for your permission! :)"); 57 | } else { 58 | console.log("You will not able to retrieve wifi available networks list"); 59 | } 60 | } catch (err) { 61 | console.warn(err) 62 | } 63 | } 64 | 65 | serviceCheckOnPress(){ 66 | wifi.isEnabled( 67 | (isEnabled)=>{ 68 | this.setState({isWifiNetworkEnabled: isEnabled}); 69 | console.log(isEnabled); 70 | }); 71 | } 72 | 73 | serviceSetEnableOnPress(enabled){ 74 | wifi.setEnabled(enabled) 75 | } 76 | 77 | connectOnPress(){ 78 | wifi.findAndConnect(this.state.ssid, this.state.pass, (found) => { 79 | this.setState({ssidExist:found}); 80 | }); 81 | } 82 | 83 | disconnectOnPress(){ 84 | wifi.disconnect(); 85 | } 86 | 87 | getSSIDOnPress(){ 88 | wifi.getSSID((ssid) => { 89 | this.setState({currentSSID:ssid}); 90 | }); 91 | } 92 | 93 | getBSSIDOnPress(){ 94 | wifi.getBSSID((bssid) => { 95 | this.setState({currentBSSID:bssid}); 96 | }); 97 | } 98 | 99 | getWifiNetworksOnPress(){ 100 | wifi.loadWifiList((wifiStringList) => { 101 | console.log(wifiStringList); 102 | var wifiArray = JSON.parse(wifiStringList); 103 | this.setState({ 104 | wifiList:wifiArray, 105 | modalVisible: true 106 | }); 107 | }, 108 | (error) => { 109 | console.log(error); 110 | } 111 | ); 112 | } 113 | 114 | connectionStatusOnPress(){ 115 | wifi.connectionStatus((isConnected) => { 116 | this.setState({status:isConnected}); 117 | }); 118 | } 119 | 120 | levelOnPress(){ 121 | wifi.getCurrentSignalStrength((level)=>{ 122 | this.setState({level:level}); 123 | }); 124 | } 125 | 126 | ipOnPress(){ 127 | wifi.getIP((ip)=>{ 128 | this.setState({ip:ip}); 129 | }); 130 | } 131 | 132 | 133 | renderModal(){ 134 | var wifiListComponents = []; 135 | for (w in this.state.wifiList){ 136 | wifiListComponents.push( 137 | 138 | {this.state.wifiList[w].SSID} 139 | BSSID: {this.state.wifiList[w].BSSID} 140 | Capabilities: {this.state.wifiList[w].capabilities} 141 | Frequency: {this.state.wifiList[w].frequency} 142 | Level: {this.state.wifiList[w].level} 143 | Timestamp: {this.state.wifiList[w].timestamp} 144 | 145 | ); 146 | } 147 | return wifiListComponents; 148 | } 149 | 150 | render() { 151 | return ( 152 | 153 | 154 | React Native Android Wifi Example App 155 | 156 | Check wifi service status 157 | 158 | 159 | Check 160 | 161 | {this.state.isWifiNetworkEnabled==null?"":this.state.isWifiNetworkEnabled?"Wifi service enabled :)":"Wifi service disabled :("} 162 | 163 | 164 | 165 | Enable/Disable wifi network 166 | 167 | 168 | Enable 169 | 170 | 171 | Disable 172 | 173 | 174 | 175 | 176 | Sign device into a specific network: 177 | SSID 178 | this.state.ssid=event} 182 | value={this.state.ssid} 183 | placeholder={'ssid'} /> 184 | Password 185 | this.state.pass=event} 190 | value={this.state.pass} 191 | placeholder={'password'} /> 192 | 193 | 194 | Connect 195 | 196 | {this.state.ssidExist==null?"":this.state.ssidExist?"Network in range :)":"Network out of range :("} 197 | 198 | 199 | 200 | Disconnect current wifi network 201 | 202 | 203 | Disconnect 204 | 205 | 206 | 207 | 208 | Current SSID 209 | 210 | 211 | Get SSID 212 | 213 | {this.state.currentSSID + ""} 214 | 215 | 216 | 217 | Current BSSID 218 | 219 | 220 | Get BSSID 221 | 222 | {this.state.currentBSSID + ""} 223 | 224 | 225 | 226 | Get all wifi networks in range 227 | 228 | Available WIFI Networks 229 | 230 | 231 | 232 | Connection status 233 | 234 | 235 | Get connection status 236 | 237 | {this.state.status==null?"":this.state.status?"You're connected :)":"You're not connected :("} 238 | 239 | 240 | 241 | Get current wifi signal strength 242 | 243 | 244 | Get signal strength 245 | 246 | {this.state.level==null?"":this.state.level} 247 | 248 | 249 | 250 | Get current IP 251 | 252 | 253 | Get IP 254 | 255 | {this.state.ip==null?"":this.state.ip} 256 | 257 | 258 | 259 | {}}> 262 | this.setState({modalVisible:false})}> 263 | Close 264 | 265 | 266 | {this.renderModal()} 267 | 268 | 269 | 270 | ); 271 | } 272 | } 273 | 274 | const styles = StyleSheet.create({ 275 | container: { 276 | flex: 1, 277 | padding:15, 278 | backgroundColor: '#F5FCFF', 279 | marginBottom:100 280 | }, 281 | row:{ 282 | flexDirection:'row' 283 | }, 284 | title: { 285 | fontSize: 20, 286 | }, 287 | instructionsContainer: { 288 | padding:15, 289 | borderBottomWidth: 1, 290 | borderBottomColor: '#CCCCCC', 291 | }, 292 | instructionsTitle: { 293 | marginBottom:10, 294 | color: '#333333' 295 | }, 296 | instructions: { 297 | color: '#333333' 298 | }, 299 | button:{ 300 | padding:5, 301 | width:120, 302 | alignItems: 'center', 303 | backgroundColor:'blue', 304 | marginRight: 15, 305 | }, 306 | bigButton:{ 307 | padding:5, 308 | width:180, 309 | alignItems: 'center', 310 | backgroundColor:'blue', 311 | marginRight: 15, 312 | }, 313 | buttonText:{ 314 | color:'white' 315 | }, 316 | answer:{ 317 | marginTop: 5, 318 | } 319 | }); 320 | -------------------------------------------------------------------------------- /Examples/Example/android/app/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | lib_deps = [] 12 | 13 | for jarfile in glob(['libs/*.jar']): 14 | name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')] 15 | lib_deps.append(':' + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | 21 | for aarfile in glob(['libs/*.aar']): 22 | name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')] 23 | lib_deps.append(':' + name) 24 | android_prebuilt_aar( 25 | name = name, 26 | aar = aarfile, 27 | ) 28 | 29 | android_library( 30 | name = "all-libs", 31 | exported_deps = lib_deps, 32 | ) 33 | 34 | android_library( 35 | name = "app-code", 36 | srcs = glob([ 37 | "src/main/java/**/*.java", 38 | ]), 39 | deps = [ 40 | ":all-libs", 41 | ":build_config", 42 | ":res", 43 | ], 44 | ) 45 | 46 | android_build_config( 47 | name = "build_config", 48 | package = "com.example", 49 | ) 50 | 51 | android_resource( 52 | name = "res", 53 | package = "com.example", 54 | res = "src/main/res", 55 | ) 56 | 57 | android_binary( 58 | name = "app", 59 | keystore = "//android/keystores:debug", 60 | manifest = "src/main/AndroidManifest.xml", 61 | package_type = "debug", 62 | deps = [ 63 | ":app-code", 64 | ], 65 | ) 66 | -------------------------------------------------------------------------------- /Examples/Example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // whether to bundle JS and assets in debug mode 22 | * bundleInDebug: false, 23 | * 24 | * // whether to bundle JS and assets in release mode 25 | * bundleInRelease: true, 26 | * 27 | * // whether to bundle JS and assets in another build variant (if configured). 28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 29 | * // The configuration property can be in the following formats 30 | * // 'bundleIn${productFlavor}${buildType}' 31 | * // 'bundleIn${buildType}' 32 | * // bundleInFreeDebug: true, 33 | * // bundleInPaidRelease: true, 34 | * // bundleInBeta: true, 35 | * 36 | * // whether to disable dev mode in custom build variants (by default only disabled in release) 37 | * // for example: to disable dev mode in the staging build type (if configured) 38 | * devDisabledInStaging: true, 39 | * // The configuration property can be in the following formats 40 | * // 'devDisabledIn${productFlavor}${buildType}' 41 | * // 'devDisabledIn${buildType}' 42 | * 43 | * // the root of your project, i.e. where "package.json" lives 44 | * root: "../../", 45 | * 46 | * // where to put the JS bundle asset in debug mode 47 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 48 | * 49 | * // where to put the JS bundle asset in release mode 50 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 51 | * 52 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 53 | * // require('./image.png')), in debug mode 54 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 55 | * 56 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 57 | * // require('./image.png')), in release mode 58 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 59 | * 60 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 61 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 62 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 63 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 64 | * // for example, you might want to remove it from here. 65 | * inputExcludes: ["android/**", "ios/**"], 66 | * 67 | * // override which node gets called and with what additional arguments 68 | * nodeExecutableAndArgs: ["node"], 69 | * 70 | * // supply additional arguments to the packager 71 | * extraPackagerArgs: [] 72 | * ] 73 | */ 74 | 75 | project.ext.react = [ 76 | entryFile: "index.js" 77 | ] 78 | 79 | apply from: "../../node_modules/react-native/react.gradle" 80 | 81 | /** 82 | * Set this to true to create two separate APKs instead of one: 83 | * - An APK that only works on ARM devices 84 | * - An APK that only works on x86 devices 85 | * The advantage is the size of the APK is reduced by about 4MB. 86 | * Upload all the APKs to the Play Store and people will download 87 | * the correct one based on the CPU architecture of their device. 88 | */ 89 | def enableSeparateBuildPerCPUArchitecture = false 90 | 91 | /** 92 | * Run Proguard to shrink the Java bytecode in release builds. 93 | */ 94 | def enableProguardInReleaseBuilds = false 95 | 96 | android { 97 | compileSdkVersion 23 98 | buildToolsVersion "23.0.1" 99 | 100 | defaultConfig { 101 | applicationId "com.example" 102 | minSdkVersion 16 103 | targetSdkVersion 22 104 | versionCode 1 105 | versionName "1.0" 106 | ndk { 107 | abiFilters "armeabi-v7a", "x86" 108 | } 109 | } 110 | splits { 111 | abi { 112 | reset() 113 | enable enableSeparateBuildPerCPUArchitecture 114 | universalApk false // If true, also generate a universal APK 115 | include "armeabi-v7a", "x86" 116 | } 117 | } 118 | buildTypes { 119 | release { 120 | minifyEnabled enableProguardInReleaseBuilds 121 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 122 | } 123 | } 124 | // applicationVariants are e.g. debug, release 125 | applicationVariants.all { variant -> 126 | variant.outputs.each { output -> 127 | // For each separate APK per architecture, set a unique version code as described here: 128 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 129 | def versionCodes = ["armeabi-v7a":1, "x86":2] 130 | def abi = output.getFilter(OutputFile.ABI) 131 | if (abi != null) { // null for the universal-debug, universal-release variants 132 | output.versionCodeOverride = 133 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 134 | } 135 | } 136 | } 137 | } 138 | 139 | dependencies { 140 | compile project(':react-native-android-wifi') 141 | compile fileTree(dir: "libs", include: ["*.jar"]) 142 | compile "com.android.support:appcompat-v7:23.0.1" 143 | compile "com.facebook.react:react-native:+" // From node_modules 144 | } 145 | 146 | // Run this once to be able to run the application with BUCK 147 | // puts all compile dependencies into folder libs for BUCK to use 148 | task copyDownloadableDepsToLibs(type: Copy) { 149 | from configurations.compile 150 | into 'libs' 151 | } 152 | -------------------------------------------------------------------------------- /Examples/Example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip 30 | 31 | # Do not strip any method/class that is annotated with @DoNotStrip 32 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 33 | -keep @com.facebook.common.internal.DoNotStrip class * 34 | -keepclassmembers class * { 35 | @com.facebook.proguard.annotations.DoNotStrip *; 36 | @com.facebook.common.internal.DoNotStrip *; 37 | } 38 | 39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 40 | void set*(***); 41 | *** get*(); 42 | } 43 | 44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 46 | -keepclassmembers,includedescriptorclasses class * { native ; } 47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } 49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } 50 | 51 | -dontwarn com.facebook.react.** 52 | 53 | # TextLayoutBuilder uses a non-public Android constructor within StaticLayout. 54 | # See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details. 55 | -dontwarn android.text.StaticLayout 56 | 57 | # okhttp 58 | 59 | -keepattributes Signature 60 | -keepattributes *Annotation* 61 | -keep class okhttp3.** { *; } 62 | -keep interface okhttp3.** { *; } 63 | -dontwarn okhttp3.** 64 | 65 | # okio 66 | 67 | -keep class sun.misc.Unsafe { *; } 68 | -dontwarn java.nio.file.* 69 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 70 | -dontwarn okio.** 71 | -------------------------------------------------------------------------------- /Examples/Example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 13 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Examples/Example/android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "Example"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Examples/Example/android/app/src/main/java/com/example/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import android.app.Application; 4 | 5 | import com.facebook.react.ReactApplication; 6 | import com.devstepbcn.wifi.AndroidWifiPackage; 7 | import com.facebook.react.ReactNativeHost; 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.shell.MainReactPackage; 10 | import com.facebook.soloader.SoLoader; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | public class MainApplication extends Application implements ReactApplication { 16 | 17 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 18 | @Override 19 | public boolean getUseDeveloperSupport() { 20 | return BuildConfig.DEBUG; 21 | } 22 | 23 | @Override 24 | protected List getPackages() { 25 | return Arrays.asList( 26 | new MainReactPackage(), 27 | new AndroidWifiPackage() 28 | ); 29 | } 30 | 31 | @Override 32 | protected String getJSMainModuleName() { 33 | return "index"; 34 | } 35 | }; 36 | 37 | @Override 38 | public ReactNativeHost getReactNativeHost() { 39 | return mReactNativeHost; 40 | } 41 | 42 | @Override 43 | public void onCreate() { 44 | super.onCreate(); 45 | SoLoader.init(this, /* native exopackage */ false); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Examples/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/Examples/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/Examples/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/Examples/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/Examples/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/Example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Example 3 | 4 | -------------------------------------------------------------------------------- /Examples/Example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Examples/Example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | mavenLocal() 18 | jcenter() 19 | maven { 20 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 21 | url "$rootDir/../node_modules/react-native/android" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Examples/Example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /Examples/Example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/Examples/Example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Examples/Example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 6 | -------------------------------------------------------------------------------- /Examples/Example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /Examples/Example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Examples/Example/android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = "debug", 3 | properties = "debug.keystore.properties", 4 | store = "debug.keystore", 5 | visibility = [ 6 | "PUBLIC", 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /Examples/Example/android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | key.store=debug.keystore 2 | key.alias=androiddebugkey 3 | key.store.password=android 4 | key.alias.password=android 5 | -------------------------------------------------------------------------------- /Examples/Example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Example' 2 | include ':react-native-android-wifi' 3 | project(':react-native-android-wifi').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-wifi/android') 4 | 5 | include ':app' 6 | -------------------------------------------------------------------------------- /Examples/Example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Example", 3 | "displayName": "Example" 4 | } -------------------------------------------------------------------------------- /Examples/Example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './App'; 3 | 4 | AppRegistry.registerComponent('Example', () => App); 5 | -------------------------------------------------------------------------------- /Examples/Example/ios/Example-tvOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UIViewControllerBasedStatusBarAppearance 38 | 39 | NSLocationWhenInUseUsageDescription 40 | 41 | NSAppTransportSecurity 42 | 43 | 44 | NSExceptionDomains 45 | 46 | localhost 47 | 48 | NSExceptionAllowsInsecureHTTPLoads 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Examples/Example/ios/Example-tvOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Examples/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example-tvOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 94 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 113 | 119 | 120 | 121 | 122 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Examples/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 94 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 113 | 119 | 120 | 121 | 122 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Examples/Example/ios/Example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | @interface AppDelegate : UIResponder 11 | 12 | @property (nonatomic, strong) UIWindow *window; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Examples/Example/ios/Example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import "AppDelegate.h" 9 | 10 | #import 11 | #import 12 | 13 | @implementation AppDelegate 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 16 | { 17 | NSURL *jsCodeLocation; 18 | 19 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 20 | 21 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 22 | moduleName:@"Example" 23 | initialProperties:nil 24 | launchOptions:launchOptions]; 25 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 26 | 27 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 28 | UIViewController *rootViewController = [UIViewController new]; 29 | rootViewController.view = rootView; 30 | self.window.rootViewController = rootViewController; 31 | [self.window makeKeyAndVisible]; 32 | return YES; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Examples/Example/ios/Example/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Examples/Example/ios/Example/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Examples/Example/ios/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UIViewControllerBasedStatusBarAppearance 40 | 41 | NSLocationWhenInUseUsageDescription 42 | 43 | NSAppTransportSecurity 44 | 45 | 46 | NSExceptionDomains 47 | 48 | localhost 49 | 50 | NSExceptionAllowsInsecureHTTPLoads 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Examples/Example/ios/Example/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Examples/Example/ios/ExampleTests/ExampleTests.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | #import 10 | 11 | #import 12 | #import 13 | 14 | #define TIMEOUT_SECONDS 600 15 | #define TEXT_TO_LOOK_FOR @"Welcome to React Native!" 16 | 17 | @interface ExampleTests : XCTestCase 18 | 19 | @end 20 | 21 | @implementation ExampleTests 22 | 23 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 24 | { 25 | if (test(view)) { 26 | return YES; 27 | } 28 | for (UIView *subview in [view subviews]) { 29 | if ([self findSubviewInView:subview matching:test]) { 30 | return YES; 31 | } 32 | } 33 | return NO; 34 | } 35 | 36 | - (void)testRendersWelcomeScreen 37 | { 38 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 39 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 40 | BOOL foundElement = NO; 41 | 42 | __block NSString *redboxError = nil; 43 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 44 | if (level >= RCTLogLevelError) { 45 | redboxError = message; 46 | } 47 | }); 48 | 49 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 50 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 51 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 52 | 53 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 54 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 55 | return YES; 56 | } 57 | return NO; 58 | }]; 59 | } 60 | 61 | RCTSetLogFunction(RCTDefaultLogFunction); 62 | 63 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 64 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 65 | } 66 | 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /Examples/Example/ios/ExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Examples/Example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start", 7 | "test": "jest" 8 | }, 9 | "dependencies": { 10 | "react": "16.3.1", 11 | "react-native": "0.55.4", 12 | "react-native-android-wifi": "0.0.39" 13 | }, 14 | "devDependencies": { 15 | "babel-jest": "23.0.1", 16 | "babel-preset-react-native": "4.0.0", 17 | "jest": "23.1.0", 18 | "react-test-renderer": "16.3.1" 19 | }, 20 | "jest": { 21 | "preset": "react-native" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react-native"] 3 | } 4 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | 16 | ; Ignore polyfills 17 | .*/Libraries/polyfills/.* 18 | 19 | ; Ignore metro 20 | .*/node_modules/metro/.* 21 | 22 | [include] 23 | 24 | [libs] 25 | node_modules/react-native/Libraries/react-native/react-native-interface.js 26 | node_modules/react-native/flow/ 27 | node_modules/react-native/flow-github/ 28 | 29 | [options] 30 | emoji=true 31 | 32 | module.system=haste 33 | 34 | munge_underscores=true 35 | 36 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 37 | 38 | module.file_ext=.js 39 | module.file_ext=.jsx 40 | module.file_ext=.json 41 | module.file_ext=.native.js 42 | 43 | suppress_type=$FlowIssue 44 | suppress_type=$FlowFixMe 45 | suppress_type=$FlowFixMeProps 46 | suppress_type=$FlowFixMeState 47 | 48 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 49 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 50 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 51 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 52 | 53 | [version] 54 | ^0.67.0 55 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://docs.fastlane.tools/best-practices/source-control/ 50 | 51 | */fastlane/report.xml 52 | */fastlane/Preview.html 53 | */fastlane/screenshots 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /Examples/ExampleAPI25/App.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { 9 | Modal, 10 | StyleSheet, 11 | Text, 12 | TextInput, 13 | TouchableHighlight, 14 | ScrollView, 15 | View, 16 | PermissionsAndroid 17 | } from 'react-native'; 18 | 19 | import wifi from 'react-native-android-wifi'; 20 | 21 | type Props = {}; 22 | export default class App extends Component { 23 | constructor(props){ 24 | super(props); 25 | this.state = { 26 | isWifiNetworkEnabled: null, 27 | ssid: null, 28 | pass: null, 29 | ssidExist: null, 30 | currentSSID: null, 31 | currentBSSID: null, 32 | wifiList: null, 33 | modalVisible: false, 34 | status:null, 35 | level: null, 36 | ip: null, 37 | }; 38 | 39 | } 40 | 41 | componentDidMount (){ 42 | console.log(wifi); 43 | this.askForUserPermissions(); 44 | } 45 | 46 | async askForUserPermissions() { 47 | try { 48 | const granted = await PermissionsAndroid.request( 49 | PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, 50 | { 51 | 'title': 'Wifi networks', 52 | 'message': 'We need your permission in order to find wifi networks' 53 | } 54 | ) 55 | if (granted === PermissionsAndroid.RESULTS.GRANTED) { 56 | console.log("Thank you for your permission! :)"); 57 | } else { 58 | console.log("You will not able to retrieve wifi available networks list"); 59 | } 60 | } catch (err) { 61 | console.warn(err) 62 | } 63 | } 64 | 65 | serviceCheckOnPress(){ 66 | wifi.isEnabled( 67 | (isEnabled)=>{ 68 | this.setState({isWifiNetworkEnabled: isEnabled}); 69 | console.log(isEnabled); 70 | }); 71 | } 72 | 73 | serviceSetEnableOnPress(enabled){ 74 | wifi.setEnabled(enabled) 75 | } 76 | 77 | connectOnPress(){ 78 | wifi.findAndConnect(this.state.ssid, this.state.pass, (found) => { 79 | this.setState({ssidExist:found}); 80 | }); 81 | } 82 | 83 | disconnectOnPress(){ 84 | wifi.disconnect(); 85 | } 86 | 87 | getSSIDOnPress(){ 88 | wifi.getSSID((ssid) => { 89 | this.setState({currentSSID:ssid}); 90 | }); 91 | } 92 | 93 | getBSSIDOnPress(){ 94 | wifi.getBSSID((bssid) => { 95 | this.setState({currentBSSID:bssid}); 96 | }); 97 | } 98 | 99 | getWifiNetworksOnPress(){ 100 | wifi.loadWifiList((wifiStringList) => { 101 | console.log(wifiStringList); 102 | var wifiArray = JSON.parse(wifiStringList); 103 | this.setState({ 104 | wifiList:wifiArray, 105 | modalVisible: true 106 | }); 107 | }, 108 | (error) => { 109 | console.log(error); 110 | } 111 | ); 112 | } 113 | 114 | connectionStatusOnPress(){ 115 | wifi.connectionStatus((isConnected) => { 116 | this.setState({status:isConnected}); 117 | }); 118 | } 119 | 120 | levelOnPress(){ 121 | wifi.getCurrentSignalStrength((level)=>{ 122 | this.setState({level:level}); 123 | }); 124 | } 125 | 126 | ipOnPress(){ 127 | wifi.getIP((ip)=>{ 128 | this.setState({ip:ip}); 129 | }); 130 | } 131 | 132 | 133 | renderModal(){ 134 | var wifiListComponents = []; 135 | for (w in this.state.wifiList){ 136 | wifiListComponents.push( 137 | 138 | {this.state.wifiList[w].SSID} 139 | BSSID: {this.state.wifiList[w].BSSID} 140 | Capabilities: {this.state.wifiList[w].capabilities} 141 | Frequency: {this.state.wifiList[w].frequency} 142 | Level: {this.state.wifiList[w].level} 143 | Timestamp: {this.state.wifiList[w].timestamp} 144 | 145 | ); 146 | } 147 | return wifiListComponents; 148 | } 149 | 150 | render() { 151 | return ( 152 | 153 | 154 | React Native Android Wifi Example App 155 | 156 | Check wifi service status 157 | 158 | 159 | Check 160 | 161 | {this.state.isWifiNetworkEnabled==null?"":this.state.isWifiNetworkEnabled?"Wifi service enabled :)":"Wifi service disabled :("} 162 | 163 | 164 | 165 | Enable/Disable wifi network 166 | 167 | 168 | Enable 169 | 170 | 171 | Disable 172 | 173 | 174 | 175 | 176 | Sign device into a specific network: 177 | SSID 178 | this.state.ssid=event} 182 | value={this.state.ssid} 183 | placeholder={'ssid'} /> 184 | Password 185 | this.state.pass=event} 190 | value={this.state.pass} 191 | placeholder={'password'} /> 192 | 193 | 194 | Connect 195 | 196 | {this.state.ssidExist==null?"":this.state.ssidExist?"Network in range :)":"Network out of range :("} 197 | 198 | 199 | 200 | Disconnect current wifi network 201 | 202 | 203 | Disconnect 204 | 205 | 206 | 207 | 208 | Current SSID 209 | 210 | 211 | Get SSID 212 | 213 | {this.state.currentSSID + ""} 214 | 215 | 216 | 217 | Current BSSID 218 | 219 | 220 | Get BSSID 221 | 222 | {this.state.currentBSSID + ""} 223 | 224 | 225 | 226 | Get all wifi networks in range 227 | 228 | Available WIFI Networks 229 | 230 | 231 | 232 | Connection status 233 | 234 | 235 | Get connection status 236 | 237 | {this.state.status==null?"":this.state.status?"You're connected :)":"You're not connected :("} 238 | 239 | 240 | 241 | Get current wifi signal strength 242 | 243 | 244 | Get signal strength 245 | 246 | {this.state.level==null?"":this.state.level} 247 | 248 | 249 | 250 | Get current IP 251 | 252 | 253 | Get IP 254 | 255 | {this.state.ip==null?"":this.state.ip} 256 | 257 | 258 | 259 | {}}> 262 | this.setState({modalVisible:false})}> 263 | Close 264 | 265 | 266 | {this.renderModal()} 267 | 268 | 269 | 270 | ); 271 | } 272 | } 273 | 274 | const styles = StyleSheet.create({ 275 | container: { 276 | flex: 1, 277 | padding:15, 278 | backgroundColor: '#F5FCFF', 279 | marginBottom:100 280 | }, 281 | row:{ 282 | flexDirection:'row' 283 | }, 284 | title: { 285 | fontSize: 20, 286 | }, 287 | instructionsContainer: { 288 | padding:15, 289 | borderBottomWidth: 1, 290 | borderBottomColor: '#CCCCCC', 291 | }, 292 | instructionsTitle: { 293 | marginBottom:10, 294 | color: '#333333' 295 | }, 296 | instructions: { 297 | color: '#333333' 298 | }, 299 | button:{ 300 | padding:5, 301 | width:120, 302 | alignItems: 'center', 303 | backgroundColor:'blue', 304 | marginRight: 15, 305 | }, 306 | bigButton:{ 307 | padding:5, 308 | width:180, 309 | alignItems: 'center', 310 | backgroundColor:'blue', 311 | marginRight: 15, 312 | }, 313 | buttonText:{ 314 | color:'white' 315 | }, 316 | answer:{ 317 | marginTop: 5, 318 | } 319 | }); 320 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | lib_deps = [] 12 | 13 | for jarfile in glob(['libs/*.jar']): 14 | name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')] 15 | lib_deps.append(':' + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | 21 | for aarfile in glob(['libs/*.aar']): 22 | name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')] 23 | lib_deps.append(':' + name) 24 | android_prebuilt_aar( 25 | name = name, 26 | aar = aarfile, 27 | ) 28 | 29 | android_library( 30 | name = "all-libs", 31 | exported_deps = lib_deps, 32 | ) 33 | 34 | android_library( 35 | name = "app-code", 36 | srcs = glob([ 37 | "src/main/java/**/*.java", 38 | ]), 39 | deps = [ 40 | ":all-libs", 41 | ":build_config", 42 | ":res", 43 | ], 44 | ) 45 | 46 | android_build_config( 47 | name = "build_config", 48 | package = "com.exampleapi25", 49 | ) 50 | 51 | android_resource( 52 | name = "res", 53 | package = "com.exampleapi25", 54 | res = "src/main/res", 55 | ) 56 | 57 | android_binary( 58 | name = "app", 59 | keystore = "//android/keystores:debug", 60 | manifest = "src/main/AndroidManifest.xml", 61 | package_type = "debug", 62 | deps = [ 63 | ":app-code", 64 | ], 65 | ) 66 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // whether to bundle JS and assets in debug mode 22 | * bundleInDebug: false, 23 | * 24 | * // whether to bundle JS and assets in release mode 25 | * bundleInRelease: true, 26 | * 27 | * // whether to bundle JS and assets in another build variant (if configured). 28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 29 | * // The configuration property can be in the following formats 30 | * // 'bundleIn${productFlavor}${buildType}' 31 | * // 'bundleIn${buildType}' 32 | * // bundleInFreeDebug: true, 33 | * // bundleInPaidRelease: true, 34 | * // bundleInBeta: true, 35 | * 36 | * // whether to disable dev mode in custom build variants (by default only disabled in release) 37 | * // for example: to disable dev mode in the staging build type (if configured) 38 | * devDisabledInStaging: true, 39 | * // The configuration property can be in the following formats 40 | * // 'devDisabledIn${productFlavor}${buildType}' 41 | * // 'devDisabledIn${buildType}' 42 | * 43 | * // the root of your project, i.e. where "package.json" lives 44 | * root: "../../", 45 | * 46 | * // where to put the JS bundle asset in debug mode 47 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 48 | * 49 | * // where to put the JS bundle asset in release mode 50 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 51 | * 52 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 53 | * // require('./image.png')), in debug mode 54 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 55 | * 56 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 57 | * // require('./image.png')), in release mode 58 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 59 | * 60 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 61 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 62 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 63 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 64 | * // for example, you might want to remove it from here. 65 | * inputExcludes: ["android/**", "ios/**"], 66 | * 67 | * // override which node gets called and with what additional arguments 68 | * nodeExecutableAndArgs: ["node"], 69 | * 70 | * // supply additional arguments to the packager 71 | * extraPackagerArgs: [] 72 | * ] 73 | */ 74 | 75 | project.ext.react = [ 76 | entryFile: "index.js" 77 | ] 78 | 79 | apply from: "../../node_modules/react-native/react.gradle" 80 | 81 | /** 82 | * Set this to true to create two separate APKs instead of one: 83 | * - An APK that only works on ARM devices 84 | * - An APK that only works on x86 devices 85 | * The advantage is the size of the APK is reduced by about 4MB. 86 | * Upload all the APKs to the Play Store and people will download 87 | * the correct one based on the CPU architecture of their device. 88 | */ 89 | def enableSeparateBuildPerCPUArchitecture = false 90 | 91 | /** 92 | * Run Proguard to shrink the Java bytecode in release builds. 93 | */ 94 | def enableProguardInReleaseBuilds = false 95 | 96 | android { 97 | compileSdkVersion 25 98 | buildToolsVersion "25.0.1" 99 | 100 | defaultConfig { 101 | applicationId "com.exampleapi25" 102 | minSdkVersion 16 103 | targetSdkVersion 25 104 | versionCode 1 105 | versionName "1.0" 106 | ndk { 107 | abiFilters "armeabi-v7a", "x86" 108 | } 109 | } 110 | splits { 111 | abi { 112 | reset() 113 | enable enableSeparateBuildPerCPUArchitecture 114 | universalApk false // If true, also generate a universal APK 115 | include "armeabi-v7a", "x86" 116 | } 117 | } 118 | buildTypes { 119 | release { 120 | minifyEnabled enableProguardInReleaseBuilds 121 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 122 | } 123 | } 124 | // applicationVariants are e.g. debug, release 125 | applicationVariants.all { variant -> 126 | variant.outputs.each { output -> 127 | // For each separate APK per architecture, set a unique version code as described here: 128 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 129 | def versionCodes = ["armeabi-v7a":1, "x86":2] 130 | def abi = output.getFilter(OutputFile.ABI) 131 | if (abi != null) { // null for the universal-debug, universal-release variants 132 | output.versionCodeOverride = 133 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 134 | } 135 | } 136 | } 137 | } 138 | 139 | dependencies { 140 | compile project(':react-native-android-wifi') 141 | compile fileTree(dir: "libs", include: ["*.jar"]) 142 | compile "com.android.support:appcompat-v7:23.0.1" 143 | compile "com.facebook.react:react-native:+" // From node_modules 144 | } 145 | 146 | // Run this once to be able to run the application with BUCK 147 | // puts all compile dependencies into folder libs for BUCK to use 148 | task copyDownloadableDepsToLibs(type: Copy) { 149 | from configurations.compile 150 | into 'libs' 151 | } 152 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip 30 | 31 | # Do not strip any method/class that is annotated with @DoNotStrip 32 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 33 | -keep @com.facebook.common.internal.DoNotStrip class * 34 | -keepclassmembers class * { 35 | @com.facebook.proguard.annotations.DoNotStrip *; 36 | @com.facebook.common.internal.DoNotStrip *; 37 | } 38 | 39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 40 | void set*(***); 41 | *** get*(); 42 | } 43 | 44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 46 | -keepclassmembers,includedescriptorclasses class * { native ; } 47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } 49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } 50 | 51 | -dontwarn com.facebook.react.** 52 | 53 | # TextLayoutBuilder uses a non-public Android constructor within StaticLayout. 54 | # See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details. 55 | -dontwarn android.text.StaticLayout 56 | 57 | # okhttp 58 | 59 | -keepattributes Signature 60 | -keepattributes *Annotation* 61 | -keep class okhttp3.** { *; } 62 | -keep interface okhttp3.** { *; } 63 | -dontwarn okhttp3.** 64 | 65 | # okio 66 | 67 | -keep class sun.misc.Unsafe { *; } 68 | -dontwarn java.nio.file.* 69 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 70 | -dontwarn okio.** 71 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 13 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/src/main/java/com/exampleapi25/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.exampleapi25; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "ExampleAPI25"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/src/main/java/com/exampleapi25/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.exampleapi25; 2 | 3 | import android.app.Application; 4 | 5 | import com.facebook.react.ReactApplication; 6 | import com.devstepbcn.wifi.AndroidWifiPackage; 7 | import com.facebook.react.ReactNativeHost; 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.shell.MainReactPackage; 10 | import com.facebook.soloader.SoLoader; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | public class MainApplication extends Application implements ReactApplication { 16 | 17 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 18 | @Override 19 | public boolean getUseDeveloperSupport() { 20 | return BuildConfig.DEBUG; 21 | } 22 | 23 | @Override 24 | protected List getPackages() { 25 | return Arrays.asList( 26 | new MainReactPackage(), 27 | new AndroidWifiPackage() 28 | ); 29 | } 30 | 31 | @Override 32 | protected String getJSMainModuleName() { 33 | return "index"; 34 | } 35 | }; 36 | 37 | @Override 38 | public ReactNativeHost getReactNativeHost() { 39 | return mReactNativeHost; 40 | } 41 | 42 | @Override 43 | public void onCreate() { 44 | super.onCreate(); 45 | SoLoader.init(this, /* native exopackage */ false); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/Examples/ExampleAPI25/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/Examples/ExampleAPI25/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/Examples/ExampleAPI25/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/Examples/ExampleAPI25/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ExampleAPI25 3 | 4 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | mavenLocal() 18 | jcenter() 19 | maven { 20 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 21 | url "$rootDir/../node_modules/react-native/android" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/Examples/ExampleAPI25/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 6 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = "debug", 3 | properties = "debug.keystore.properties", 4 | store = "debug.keystore", 5 | visibility = [ 6 | "PUBLIC", 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | key.store=debug.keystore 2 | key.alias=androiddebugkey 3 | key.store.password=android 4 | key.alias.password=android 5 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'ExampleAPI25' 2 | include ':react-native-android-wifi' 3 | project(':react-native-android-wifi').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-wifi/android') 4 | 5 | include ':app' 6 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ExampleAPI25", 3 | "displayName": "ExampleAPI25" 4 | } -------------------------------------------------------------------------------- /Examples/ExampleAPI25/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './App'; 3 | 4 | AppRegistry.registerComponent('ExampleAPI25', () => App); 5 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25-tvOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UIViewControllerBasedStatusBarAppearance 38 | 39 | NSLocationWhenInUseUsageDescription 40 | 41 | NSAppTransportSecurity 42 | 43 | 44 | NSExceptionDomains 45 | 46 | localhost 47 | 48 | NSExceptionAllowsInsecureHTTPLoads 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25-tvOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25.xcodeproj/xcshareddata/xcschemes/ExampleAPI25-tvOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 94 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 113 | 119 | 120 | 121 | 122 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25.xcodeproj/xcshareddata/xcschemes/ExampleAPI25.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 94 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 113 | 119 | 120 | 121 | 122 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | @interface AppDelegate : UIResponder 11 | 12 | @property (nonatomic, strong) UIWindow *window; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import "AppDelegate.h" 9 | 10 | #import 11 | #import 12 | 13 | @implementation AppDelegate 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 16 | { 17 | NSURL *jsCodeLocation; 18 | 19 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 20 | 21 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 22 | moduleName:@"ExampleAPI25" 23 | initialProperties:nil 24 | launchOptions:launchOptions]; 25 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 26 | 27 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 28 | UIViewController *rootViewController = [UIViewController new]; 29 | rootViewController.view = rootView; 30 | self.window.rootViewController = rootViewController; 31 | [self.window makeKeyAndVisible]; 32 | return YES; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ExampleAPI25 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UIViewControllerBasedStatusBarAppearance 40 | 41 | NSLocationWhenInUseUsageDescription 42 | 43 | NSAppTransportSecurity 44 | 45 | 46 | NSExceptionDomains 47 | 48 | localhost 49 | 50 | NSExceptionAllowsInsecureHTTPLoads 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25Tests/ExampleAPI25Tests.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | #import 10 | 11 | #import 12 | #import 13 | 14 | #define TIMEOUT_SECONDS 600 15 | #define TEXT_TO_LOOK_FOR @"Welcome to React Native!" 16 | 17 | @interface ExampleAPI25Tests : XCTestCase 18 | 19 | @end 20 | 21 | @implementation ExampleAPI25Tests 22 | 23 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 24 | { 25 | if (test(view)) { 26 | return YES; 27 | } 28 | for (UIView *subview in [view subviews]) { 29 | if ([self findSubviewInView:subview matching:test]) { 30 | return YES; 31 | } 32 | } 33 | return NO; 34 | } 35 | 36 | - (void)testRendersWelcomeScreen 37 | { 38 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 39 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 40 | BOOL foundElement = NO; 41 | 42 | __block NSString *redboxError = nil; 43 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 44 | if (level >= RCTLogLevelError) { 45 | redboxError = message; 46 | } 47 | }); 48 | 49 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 50 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 51 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 52 | 53 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 54 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 55 | return YES; 56 | } 57 | return NO; 58 | }]; 59 | } 60 | 61 | RCTSetLogFunction(RCTDefaultLogFunction); 62 | 63 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 64 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 65 | } 66 | 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/ios/ExampleAPI25Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Examples/ExampleAPI25/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ExampleAPI25", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start", 7 | "test": "jest" 8 | }, 9 | "dependencies": { 10 | "react": "16.3.1", 11 | "react-native": "0.55.4", 12 | "react-native-android-wifi": "0.0.39" 13 | }, 14 | "devDependencies": { 15 | "babel-jest": "23.0.1", 16 | "babel-preset-react-native": "4.0.0", 17 | "jest": "23.1.0", 18 | "react-test-renderer": "16.3.1" 19 | }, 20 | "jest": { 21 | "preset": "react-native" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Ferran Reventos Creus 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-android-wifi 2 | 3 | A react-native module for viewing and connecting to Wifi networks on Android devices. 4 | 5 | ![example app](/docs/example-app.gif) 6 | 7 | ### Installation 8 | 9 | ### Add it to your android project 10 | ```bash 11 | npm install react-native-android-wifi --save 12 | ``` 13 | 14 | ### Install the native dependencies 15 | Use react-native link to install native dependencies automatically: 16 | ```bash 17 | react-native link react-native-android-wifi 18 | ``` 19 | or do it manually as described [here](docs/link-manually.md). 20 | 21 | ### Example usage 22 | 23 | ```javascript 24 | import wifi from 'react-native-android-wifi'; 25 | ``` 26 | 27 | Permissions: Starting with Android API 25, apps must be granted the ACCESS_COARSE_LOCATION (or ACCESS_FINE_LOCATION) permission in order to obtain results. 28 | ```javascript 29 | try { 30 | const granted = await PermissionsAndroid.request( 31 | PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, 32 | { 33 | 'title': 'Wifi networks', 34 | 'message': 'We need your permission in order to find wifi networks' 35 | } 36 | ) 37 | if (granted === PermissionsAndroid.RESULTS.GRANTED) { 38 | console.log("Thank you for your permission! :)"); 39 | } else { 40 | console.log("You will not able to retrieve wifi available networks list"); 41 | } 42 | } catch (err) { 43 | console.warn(err) 44 | } 45 | ``` 46 | 47 | Wifi connectivity status: 48 | ```javascript 49 | wifi.isEnabled((isEnabled) => { 50 | if (isEnabled) { 51 | console.log("wifi service enabled"); 52 | } else { 53 | console.log("wifi service is disabled"); 54 | } 55 | }); 56 | ``` 57 | 58 | Enable/Disable wifi service: 59 | ```javascript 60 | //Set TRUE to enable and FALSE to disable; 61 | wifi.setEnabled(true); 62 | ``` 63 | 64 | Sign device into a specific network: 65 | > This method doesn't have a callback when connection succeeded, check [this](https://github.com/devstepbcn/react-native-android-wifi/issues/4) issue. 66 | Added support for 'WPA2 PSK' wifi security mode and handling SSID for Lollipop and Kitkat. 67 | 68 | ```javascript 69 | //found returns true if ssid is in the range 70 | wifi.findAndConnect(ssid, password, (found) => { 71 | if (found) { 72 | console.log("wifi is in range"); 73 | } else { 74 | console.log("wifi is not in range"); 75 | } 76 | }); 77 | ``` 78 | 79 | Disconnect from current wifi network 80 | ```javascript 81 | wifi.disconnect(); 82 | ``` 83 | 84 | Get current SSID 85 | ```javascript 86 | wifi.getSSID((ssid) => { 87 | console.log(ssid); 88 | }); 89 | ``` 90 | 91 | Get current BSSID 92 | ```javascript 93 | wifi.getBSSID((bssid) => { 94 | console.log(bssid); 95 | }); 96 | ``` 97 | 98 | Get all wifi networks in range 99 | ```javascript 100 | /* 101 | wifiStringList is a stringified JSONArray with the following fields for each scanned wifi 102 | { 103 | "SSID": "The network name", 104 | "BSSID": "The address of the access point", 105 | "capabilities": "Describes the authentication, key management, and encryption schemes supported by the access point" 106 | "frequency":"The primary 20 MHz frequency (in MHz) of the channel over which the client is communicating with the access point", 107 | "level":"The detected signal level in dBm, also known as the RSSI. (Remember its a negative value)", 108 | "timestamp":"Timestamp in microseconds (since boot) when this result was last seen" 109 | } 110 | */ 111 | wifi.loadWifiList((wifiStringList) => { 112 | var wifiArray = JSON.parse(wifiStringList); 113 | console.log(wifiArray); 114 | }, 115 | (error) => { 116 | console.log(error); 117 | } 118 | ); 119 | ``` 120 | 121 | connectionStatus returns true or false depending on whether device is connected to wifi 122 | ```javascript 123 | wifi.connectionStatus((isConnected) => { 124 | if (isConnected) { 125 | console.log("is connected"); 126 | } else { 127 | console.log("is not connected"); 128 | } 129 | }); 130 | ``` 131 | 132 | Get connected wifi signal strength 133 | ```javascript 134 | //level is the detected signal level in dBm, also known as the RSSI. (Remember its a negative value) 135 | wifi.getCurrentSignalStrength((level) => { 136 | console.log(level); 137 | }); 138 | ``` 139 | 140 | Get connected wifi frequency 141 | ```javascript 142 | wifi.getFrequency((frequency) => { 143 | console.log(frequency); 144 | }) 145 | ``` 146 | 147 | Get current IP 148 | ```javascript 149 | //get the current network connection IP 150 | wifi.getIP((ip) => { 151 | console.log(ip); 152 | }); 153 | ``` 154 | Get DHCP Server Adress 155 | ```javascript 156 | //get the DHCP server IP 157 | wifi.getDhcpServerAddress((ip) => { 158 | console.log(ip); 159 | }); 160 | ``` 161 | 162 | Remove/Forget the Wifi network from mobile by SSID, returns boolean 163 | This method will remove the wifi network as per the passed SSID from the device list. 164 | ``` javascript 165 | wifi.isRemoveWifiNetwork(ssid, (isRemoved) => { 166 | console.log("Forgetting the wifi device - " + ssid); 167 | }); 168 | ``` 169 | 170 | Starts native Android wifi network scanning and returns list 171 | Hard refresh the Android wifi scan, implemented using `BroadcastReceiver` to ensure that it automatically detects new wifi connections available. 172 | ``` javascript 173 | wifi.reScanAndLoadWifiList((wifiStringList) => { 174 | var wifiArray = JSON.parse(wifiStringList); 175 | console.log('Detected wifi networks - ',wifiArray); 176 | },(error)=>{ 177 | console.log(error); 178 | }); 179 | ``` 180 | 181 | Method to force wifi usage. Android by default sends all requests via mobile data if the connected wifi has no internet connection. 182 | ``` javascript 183 | //Set true/false to enable/disable forceWifiUsage. 184 | //Is important to enable only when communicating with the device via wifi 185 | //and remember to disable it when disconnecting from device. 186 | wifi.forceWifiUsage(true); 187 | ``` 188 | 189 | Method to get connection status of a forced network (because it takes some time to be set up). 190 | ``` javascript 191 | //Callback returns true if the process of forcing network usage is finished 192 | wifi.connectionStatusOfBoundNetwork((isBound) => { 193 | if (isBound) { 194 | console.log('Network is bound'); 195 | } else { 196 | console.log('Network isn\'t bound'); 197 | } 198 | }); 199 | ``` 200 | 201 | 202 | Add a hidden wifi network and connect to it 203 | ``` javascript 204 | //Callback returns true if network added and tried to connect to it successfully 205 | //It may take up to 15s to connect to hidden networks 206 | wifi.connectToHiddenNetwork(ssid, password, (networkAdded) => {}); 207 | ``` -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | def DEFAULT_COMPILE_SDK_VERSION = 23 4 | def DEFAULT_BUILD_TOOLS_VERSION = "23.0.1" 5 | def DEFAULT_TARGET_SDK_VERSION = 22 6 | 7 | android { 8 | compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION 9 | buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION 10 | 11 | defaultConfig { 12 | minSdkVersion 16 13 | targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION 14 | versionCode 1 15 | versionName "1.0" 16 | } 17 | } 18 | 19 | dependencies { 20 | compile 'com.facebook.react:react-native:+' 21 | } 22 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /android/src/main/java/com/devstepbcn/wifi/AndroidWifiModule.java: -------------------------------------------------------------------------------- 1 | package com.devstepbcn.wifi; 2 | 3 | import com.facebook.react.uimanager.*; 4 | import com.facebook.react.bridge.*; 5 | import com.facebook.systrace.Systrace; 6 | import com.facebook.systrace.SystraceMessage; 7 | import com.facebook.react.ReactInstanceManager; 8 | import com.facebook.react.ReactRootView; 9 | import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; 10 | import com.facebook.react.modules.core.DeviceEventManagerModule; 11 | import com.facebook.react.shell.MainReactPackage; 12 | import com.facebook.soloader.SoLoader; 13 | import android.provider.Settings; 14 | import android.net.wifi.ScanResult; 15 | import android.net.wifi.WifiManager; 16 | import android.net.wifi.WifiConfiguration; 17 | import android.net.ConnectivityManager; 18 | import android.net.NetworkInfo; 19 | import android.net.NetworkRequest; 20 | import android.net.NetworkCapabilities; 21 | import android.net.Network; 22 | import android.net.Uri; 23 | import android.net.wifi.WifiInfo; 24 | import android.content.Context; 25 | import android.content.Intent; 26 | import android.content.IntentFilter; 27 | import android.content.BroadcastReceiver; 28 | import android.os.Build; 29 | import android.os.Bundle; 30 | import android.widget.Toast; 31 | import java.util.List; 32 | import java.lang.Thread; 33 | import android.net.DhcpInfo; 34 | 35 | import org.json.JSONArray; 36 | import org.json.JSONException; 37 | import org.json.JSONObject; 38 | 39 | public class AndroidWifiModule extends ReactContextBaseJavaModule { 40 | 41 | //WifiManager Instance 42 | WifiManager wifi; 43 | ReactApplicationContext reactContext; 44 | 45 | //Constructor 46 | public AndroidWifiModule(ReactApplicationContext reactContext) { 47 | super(reactContext); 48 | 49 | wifi = (WifiManager)reactContext.getSystemService(Context.WIFI_SERVICE); 50 | this.reactContext = reactContext; 51 | } 52 | 53 | //Name for module register to use: 54 | @Override 55 | public String getName() { 56 | return "AndroidWifiModule"; 57 | } 58 | 59 | //Method to load wifi list into string via Callback. Returns a stringified JSONArray 60 | @ReactMethod 61 | public void loadWifiList(Callback successCallback, Callback errorCallback) { 62 | try { 63 | List < ScanResult > results = wifi.getScanResults(); 64 | JSONArray wifiArray = new JSONArray(); 65 | 66 | for (ScanResult result: results) { 67 | JSONObject wifiObject = new JSONObject(); 68 | if(!result.SSID.equals("")){ 69 | try { 70 | wifiObject.put("SSID", result.SSID); 71 | wifiObject.put("BSSID", result.BSSID); 72 | wifiObject.put("capabilities", result.capabilities); 73 | wifiObject.put("frequency", result.frequency); 74 | wifiObject.put("level", result.level); 75 | wifiObject.put("timestamp", result.timestamp); 76 | //Other fields not added 77 | //wifiObject.put("operatorFriendlyName", result.operatorFriendlyName); 78 | //wifiObject.put("venueName", result.venueName); 79 | //wifiObject.put("centerFreq0", result.centerFreq0); 80 | //wifiObject.put("centerFreq1", result.centerFreq1); 81 | //wifiObject.put("channelWidth", result.channelWidth); 82 | } catch (JSONException e) { 83 | errorCallback.invoke(e.getMessage()); 84 | } 85 | wifiArray.put(wifiObject); 86 | } 87 | } 88 | successCallback.invoke(wifiArray.toString()); 89 | } catch (IllegalViewOperationException e) { 90 | errorCallback.invoke(e.getMessage()); 91 | } 92 | } 93 | 94 | //Method to force wifi usage if the user needs to send requests via wifi 95 | //if it does not have internet connection. Useful for IoT applications, when 96 | //the app needs to communicate and send requests to a device that have no 97 | //internet connection via wifi. 98 | 99 | //Receives a boolean to enable forceWifiUsage if true, and disable if false. 100 | //Is important to enable only when communicating with the device via wifi 101 | //and remember to disable it when disconnecting from device. 102 | @ReactMethod 103 | public void forceWifiUsage(boolean useWifi) { 104 | boolean canWriteFlag = false; 105 | 106 | if (useWifi) { 107 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 108 | 109 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 110 | canWriteFlag = true; 111 | // Only need ACTION_MANAGE_WRITE_SETTINGS on 6.0.0, regular permissions suffice on later versions 112 | } else if (Build.VERSION.RELEASE.toString().equals("6.0.1")) { 113 | canWriteFlag = true; 114 | // Don't need ACTION_MANAGE_WRITE_SETTINGS on 6.0.1, if we can positively identify it treat like 7+ 115 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 116 | // On M 6.0.0 (N+ or higher and 6.0.1 hit above), we need ACTION_MANAGE_WRITE_SETTINGS to forceWifi. 117 | canWriteFlag = Settings.System.canWrite(reactContext); 118 | if (!canWriteFlag) { 119 | Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); 120 | intent.setData(Uri.parse("package:" + reactContext.getPackageName())); 121 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 122 | 123 | reactContext.startActivity(intent); 124 | } 125 | } 126 | 127 | if (((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) && canWriteFlag) || ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) && !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M))) { 128 | final ConnectivityManager manager = (ConnectivityManager) reactContext 129 | .getSystemService(Context.CONNECTIVITY_SERVICE); 130 | NetworkRequest.Builder builder; 131 | builder = new NetworkRequest.Builder(); 132 | //set the transport type do WIFI 133 | builder.addTransportType(NetworkCapabilities.TRANSPORT_WIFI); 134 | 135 | 136 | manager.requestNetwork(builder.build(), new ConnectivityManager.NetworkCallback() { 137 | @Override 138 | public void onAvailable(Network network) { 139 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 140 | manager.bindProcessToNetwork(network); 141 | } else { 142 | //This method was deprecated in API level 23 143 | ConnectivityManager.setProcessDefaultNetwork(network); 144 | } 145 | try { 146 | } catch (Exception e) { 147 | e.printStackTrace(); 148 | } 149 | manager.unregisterNetworkCallback(this); 150 | } 151 | }); 152 | } 153 | } 154 | } else { 155 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 156 | ConnectivityManager manager = (ConnectivityManager) reactContext 157 | .getSystemService(Context.CONNECTIVITY_SERVICE); 158 | manager.bindProcessToNetwork(null); 159 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 160 | ConnectivityManager.setProcessDefaultNetwork(null); 161 | } 162 | } 163 | } 164 | 165 | //Use this method to make sure that your forced network already bound 166 | @ReactMethod 167 | public void connectionStatusOfBoundNetwork(Callback connectionStatusResult) { 168 | ConnectivityManager connManager = (ConnectivityManager) getReactApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); 169 | Network network = connManager.getBoundNetworkForProcess(); 170 | if (network != null) { 171 | connectionStatusResult.invoke(true); 172 | } else { 173 | connectionStatusResult.invoke(false); 174 | } 175 | } 176 | 177 | //Method to check if wifi is enabled 178 | @ReactMethod 179 | public void isEnabled(Callback isEnabled) { 180 | isEnabled.invoke(wifi.isWifiEnabled()); 181 | } 182 | 183 | //Method to connect/disconnect wifi service 184 | @ReactMethod 185 | public void setEnabled(Boolean enabled) { 186 | wifi.setWifiEnabled(enabled); 187 | } 188 | 189 | //Send the ssid and password of a Wifi network into this to connect to the network. 190 | //Example: wifi.findAndConnect(ssid, password); 191 | //After 10 seconds, a post telling you whether you are connected will pop up. 192 | //Callback returns true if ssid is in the range 193 | @ReactMethod 194 | public void findAndConnect(String ssid, String password, Callback ssidFound) { 195 | List < ScanResult > results = wifi.getScanResults(); 196 | boolean connected = false; 197 | for (ScanResult result: results) { 198 | String resultString = "" + result.SSID; 199 | if (ssid.equals(resultString)) { 200 | connected = connectTo(result, password, ssid); 201 | } 202 | } 203 | ssidFound.invoke(connected); 204 | } 205 | 206 | //Use this method to check if the device is currently connected to Wifi. 207 | @ReactMethod 208 | public void connectionStatus(Callback connectionStatusResult) { 209 | ConnectivityManager connManager = (ConnectivityManager) getReactApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); 210 | NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); 211 | if (mWifi.isConnected()) { 212 | connectionStatusResult.invoke(true); 213 | } else { 214 | connectionStatusResult.invoke(false); 215 | } 216 | } 217 | 218 | //Method to connect to WIFI Network 219 | public Boolean connectTo(ScanResult result, String password, String ssid) { 220 | //Make new configuration 221 | WifiConfiguration conf = new WifiConfiguration(); 222 | 223 | //clear alloweds 224 | conf.allowedAuthAlgorithms.clear(); 225 | conf.allowedGroupCiphers.clear(); 226 | conf.allowedKeyManagement.clear(); 227 | conf.allowedPairwiseCiphers.clear(); 228 | conf.allowedProtocols.clear(); 229 | 230 | // Quote ssid and password 231 | conf.SSID = String.format("\"%s\"", ssid); 232 | 233 | WifiConfiguration tempConfig = this.IsExist(conf.SSID); 234 | if (tempConfig != null) { 235 | wifi.removeNetwork(tempConfig.networkId); 236 | } 237 | 238 | String capabilities = result.capabilities; 239 | 240 | // appropriate ciper is need to set according to security type used 241 | if (capabilities.contains("WPA") || capabilities.contains("WPA2") || capabilities.contains("WPA/WPA2 PSK")) { 242 | 243 | // This is needed for WPA/WPA2 244 | // Reference - https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/wifi/java/android/net/wifi/WifiConfiguration.java#149 245 | conf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); 246 | 247 | conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); 248 | conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); 249 | 250 | conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); 251 | 252 | conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); 253 | conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); 254 | 255 | conf.allowedProtocols.set(WifiConfiguration.Protocol.RSN); 256 | conf.allowedProtocols.set(WifiConfiguration.Protocol.WPA); 257 | conf.status = WifiConfiguration.Status.ENABLED; 258 | conf.preSharedKey = String.format("\"%s\"", password); 259 | 260 | } else if (capabilities.contains("WEP")) { 261 | // This is needed for WEP 262 | // Reference - https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/wifi/java/android/net/wifi/WifiConfiguration.java#149 263 | conf.wepKeys[0] = "\"" + password + "\""; 264 | conf.wepTxKeyIndex = 0; 265 | conf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); 266 | conf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); 267 | conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); 268 | conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); 269 | } else { 270 | conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); 271 | } 272 | 273 | List mWifiConfigList = wifi.getConfiguredNetworks(); 274 | if (mWifiConfigList == null) { 275 | return false; 276 | } 277 | 278 | int updateNetwork = -1; 279 | 280 | // Use the existing network config if exists 281 | for (WifiConfiguration wifiConfig : mWifiConfigList) { 282 | if (wifiConfig.SSID.equals(conf.SSID)) { 283 | conf=wifiConfig; 284 | updateNetwork=conf.networkId; 285 | } 286 | } 287 | 288 | // If network not already in configured networks add new network 289 | if ( updateNetwork == -1 ) { 290 | updateNetwork = wifi.addNetwork(conf); 291 | wifi.saveConfiguration(); 292 | } 293 | 294 | // if network not added return false 295 | if ( updateNetwork == -1 ) { 296 | return false; 297 | } 298 | 299 | // disconnect current network 300 | boolean disconnect = wifi.disconnect(); 301 | if ( !disconnect ) { 302 | return false; 303 | } 304 | 305 | // enable new network 306 | boolean enableNetwork = wifi.enableNetwork(updateNetwork, true); 307 | if ( !enableNetwork ) { 308 | return false; 309 | } 310 | 311 | return true; 312 | } 313 | 314 | //add configuration of hidden network and return it's networkId 315 | public int setWifiConfig(String ssid, String sharedKey) { 316 | WifiConfiguration conf = new WifiConfiguration(); 317 | 318 | conf.SSID = "\"" + ssid + "\""; 319 | conf.preSharedKey = "\"" + sharedKey + "\""; 320 | 321 | conf.hiddenSSID = true; 322 | conf.status = WifiConfiguration.Status.ENABLED; 323 | conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); 324 | conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); 325 | conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); 326 | conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); 327 | conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); 328 | conf.allowedProtocols.set(WifiConfiguration.Protocol.RSN); 329 | conf.allowedProtocols.set(WifiConfiguration.Protocol.WPA); 330 | 331 | return wifi.addNetwork(conf); 332 | } 333 | 334 | //Add a hidden wifi network and connect to it 335 | //Example: wifi.connectToHiddenNetwork(ssid, password, (networkAdded) => {}); 336 | //Callback returns true if network added and tried to connect to it successfully 337 | //It may take up to 15s to connect to hidden networks 338 | @ReactMethod 339 | public void connectToHiddenNetwork(String ssid, String password, Callback networkAdded) { 340 | List list = wifi.getConfiguredNetworks(); 341 | if (list == null) { 342 | networkAdded.invoke(false); 343 | return; 344 | } 345 | 346 | int updateNetwork = -1; 347 | 348 | // check if network config exists and it's hidden 349 | for (WifiConfiguration wifiConfig : list) { 350 | if (wifiConfig.SSID.equals("\"" + ssid + "\"") && wifiConfig.hiddenSSID) { 351 | updateNetwork = wifiConfig.networkId; 352 | } 353 | } 354 | 355 | // If network not already in configured networks add new network 356 | if (updateNetwork == -1) { 357 | updateNetwork = setWifiConfig(ssid, password); 358 | } 359 | 360 | // if network not added return false 361 | if (updateNetwork == -1) { 362 | networkAdded.invoke(false); 363 | return; 364 | } 365 | 366 | // disconnect current network 367 | boolean disconnect = wifi.disconnect(); 368 | if (!disconnect) { 369 | networkAdded.invoke(false); 370 | return; 371 | } 372 | 373 | // enable new network 374 | boolean enableNetwork = wifi.enableNetwork(updateNetwork, true); 375 | if (!enableNetwork) { 376 | networkAdded.invoke(false); 377 | return; 378 | } 379 | 380 | // reconnect to new network 381 | boolean reconnect = wifi.reconnect(); 382 | if (!reconnect) { 383 | networkAdded.invoke(false); 384 | return; 385 | } 386 | 387 | wifi.saveConfiguration(); 388 | 389 | networkAdded.invoke(true); 390 | } 391 | 392 | //Disconnect current Wifi. 393 | @ReactMethod 394 | public void disconnect() { 395 | wifi.disconnect(); 396 | } 397 | 398 | //This method will return current ssid 399 | @ReactMethod 400 | public void getSSID(final Callback callback) { 401 | WifiInfo info = wifi.getConnectionInfo(); 402 | 403 | // This value should be wrapped in double quotes, so we need to unwrap it. 404 | String ssid = info.getSSID(); 405 | if (ssid.startsWith("\"") && ssid.endsWith("\"")) { 406 | ssid = ssid.substring(1, ssid.length() - 1); 407 | } 408 | 409 | callback.invoke(ssid); 410 | } 411 | 412 | //This method will return the basic service set identifier (BSSID) of the current access point 413 | @ReactMethod 414 | public void getBSSID(final Callback callback) { 415 | WifiInfo info = wifi.getConnectionInfo(); 416 | 417 | String bssid = info.getBSSID(); 418 | 419 | callback.invoke(bssid.toUpperCase()); 420 | } 421 | 422 | //This method will return current wifi signal strength 423 | @ReactMethod 424 | public void getCurrentSignalStrength(final Callback callback) { 425 | int linkSpeed = wifi.getConnectionInfo().getRssi(); 426 | callback.invoke(linkSpeed); 427 | } 428 | 429 | //This method will return current wifi frequency 430 | @ReactMethod 431 | public void getFrequency(final Callback callback) { 432 | WifiInfo info = wifi.getConnectionInfo(); 433 | int frequency = info.getFrequency(); 434 | callback.invoke(frequency); 435 | } 436 | 437 | //This method will return current IP 438 | @ReactMethod 439 | public void getIP(final Callback callback) { 440 | WifiInfo info = wifi.getConnectionInfo(); 441 | String stringip = longToIP(info.getIpAddress()); 442 | callback.invoke(stringip); 443 | } 444 | 445 | //This method will remove the wifi network as per the passed SSID from the device list 446 | @ReactMethod 447 | public void isRemoveWifiNetwork(String ssid, final Callback callback) { 448 | List mWifiConfigList = wifi.getConfiguredNetworks(); 449 | if (mWifiConfigList == null) { 450 | return; 451 | } 452 | 453 | for (WifiConfiguration wifiConfig : mWifiConfigList) { 454 | String comparableSSID = ('"' + ssid + '"'); //Add quotes because wifiConfig.SSID has them 455 | if(wifiConfig.SSID.equals(comparableSSID)) { 456 | wifi.removeNetwork(wifiConfig.networkId); 457 | wifi.saveConfiguration(); 458 | callback.invoke(true); 459 | return; 460 | } 461 | } 462 | callback.invoke(false); 463 | } 464 | 465 | @ReactMethod 466 | public void reScanAndLoadWifiList(Callback successCallback, Callback errorCallback) { 467 | WifiReceiver receiverWifi = new WifiReceiver(wifi, successCallback, errorCallback); 468 | getCurrentActivity().registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); 469 | wifi.startScan(); 470 | } 471 | 472 | @ReactMethod 473 | public void getDhcpServerAddress(Callback callback) { 474 | DhcpInfo dhcpInfo = wifi.getDhcpInfo(); 475 | String ip = longToIP(dhcpInfo.serverAddress); 476 | callback.invoke(ip); 477 | } 478 | 479 | public static String longToIP(int longIp){ 480 | StringBuffer sb = new StringBuffer(""); 481 | String[] strip=new String[4]; 482 | strip[3]=String.valueOf((longIp >>> 24)); 483 | strip[2]=String.valueOf((longIp & 0x00FFFFFF) >>> 16); 484 | strip[1]=String.valueOf((longIp & 0x0000FFFF) >>> 8); 485 | strip[0]=String.valueOf((longIp & 0x000000FF)); 486 | sb.append(strip[0]); 487 | sb.append("."); 488 | sb.append(strip[1]); 489 | sb.append("."); 490 | sb.append(strip[2]); 491 | sb.append("."); 492 | sb.append(strip[3]); 493 | return sb.toString(); 494 | } 495 | 496 | private WifiConfiguration IsExist(String SSID) { 497 | List existingConfigs = wifi.getConfiguredNetworks(); 498 | if (existingConfigs == null) { 499 | return null; 500 | } 501 | 502 | for (WifiConfiguration existingConfig : existingConfigs) { 503 | if (existingConfig.SSID.equals("\"" + SSID + "\"")) { 504 | return existingConfig; 505 | } 506 | } 507 | return null; 508 | } 509 | 510 | class WifiReceiver extends BroadcastReceiver { 511 | 512 | private Callback successCallback; 513 | private Callback errorCallback; 514 | private WifiManager wifi; 515 | 516 | public WifiReceiver(final WifiManager wifi, Callback successCallback, Callback errorCallback) { 517 | super(); 518 | this.successCallback = successCallback; 519 | this.errorCallback = errorCallback; 520 | this.wifi = wifi; 521 | } 522 | 523 | // This method call when number of wifi connections changed 524 | public void onReceive(Context c, Intent intent) { 525 | 526 | c.unregisterReceiver(this); 527 | 528 | try { 529 | List < ScanResult > results = this.wifi.getScanResults(); 530 | JSONArray wifiArray = new JSONArray(); 531 | 532 | for (ScanResult result: results) { 533 | JSONObject wifiObject = new JSONObject(); 534 | if(!result.SSID.equals("")){ 535 | try { 536 | wifiObject.put("SSID", result.SSID); 537 | wifiObject.put("BSSID", result.BSSID); 538 | wifiObject.put("capabilities", result.capabilities); 539 | wifiObject.put("frequency", result.frequency); 540 | wifiObject.put("level", result.level); 541 | wifiObject.put("timestamp", result.timestamp); 542 | } catch (JSONException e) { 543 | this.errorCallback.invoke(e.getMessage()); 544 | return; 545 | } 546 | wifiArray.put(wifiObject); 547 | } 548 | } 549 | this.successCallback.invoke(wifiArray.toString()); 550 | return; 551 | } catch (IllegalViewOperationException e) { 552 | this.errorCallback.invoke(e.getMessage()); 553 | return; 554 | } 555 | } 556 | } 557 | } 558 | -------------------------------------------------------------------------------- /android/src/main/java/com/devstepbcn/wifi/AndroidWifiPackage.java: -------------------------------------------------------------------------------- 1 | package com.devstepbcn.wifi; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.ArrayList; 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.bridge.JavaScriptModule; 9 | import com.facebook.react.bridge.NativeModule; 10 | import com.facebook.react.bridge.ReactApplicationContext; 11 | import com.facebook.react.uimanager.ViewManager; 12 | 13 | public class AndroidWifiPackage implements ReactPackage { 14 | 15 | @Override 16 | public List createNativeModules(ReactApplicationContext reactContext) { 17 | List modules = new ArrayList<>(); 18 | modules.add(new AndroidWifiModule(reactContext)); 19 | return modules; 20 | } 21 | 22 | // This method is kept for RN < 0.47 compatibility 23 | public List> createJSModules() { 24 | return Collections.emptyList(); 25 | } 26 | 27 | @Override 28 | public List createViewManagers(ReactApplicationContext reactContext) { 29 | return Arrays.asList(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /docs/example-app.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devstepbcn/react-native-android-wifi/a05db17e6cc3cabc44d686848bd2e73dd3fc1ed9/docs/example-app.gif -------------------------------------------------------------------------------- /docs/link-manually.md: -------------------------------------------------------------------------------- 1 | # react-native-android-wifi 2 | ## Link Manually 3 | 4 | * In `android/setting.gradle` 5 | ```gradle 6 | ... 7 | include ':app' 8 | include ':react-native-android-wifi' 9 | project(':react-native-android-wifi').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-wifi/android') 10 | ``` 11 | 12 | * In `android/app/build.gradle` 13 | 14 | ```gradle 15 | ... 16 | dependencies { 17 | ... 18 | compile project(':react-native-android-wifi') 19 | } 20 | ``` 21 | 22 | On newer versions of React Native (0.29.0+): 23 | * register module (in MainApplication.java) 24 | 25 | 26 | ```java 27 | import com.devstepbcn.wifi.AndroidWifiPackage; // <--- import 28 | 29 | public class MainApplication extends Application implements ReactApplication { 30 | ...... 31 | 32 | @Override 33 | protected List getPackages() { 34 | return Arrays.asList( 35 | new MainReactPackage(), 36 | new AndroidWifiPackage(), // <------ add here 37 | ); 38 | } 39 | }; 40 | ``` 41 | 42 | On older versions of React Native (>=0.18<0.29.0): 43 | 44 | * register module (in MainActivity.java) 45 | 46 | ```java 47 | import com.devstepbcn.wifi.AndroidWifiPackage; // <--- import 48 | 49 | public class MainActivity extends ReactActivity { 50 | ...... 51 | 52 | /** 53 | * A list of packages used by the app. If the app uses additional views 54 | * or modules besides the default ones, add more packages here. 55 | */ 56 | @Override 57 | protected List getPackages() { 58 | return Arrays.asList( 59 | new AndroidWifiPackage(), // <------ add here 60 | new MainReactPackage()); 61 | } 62 | } 63 | ``` 64 | 65 | On older versions of React Native: 66 | 67 | * register module (in MainActivity.java) 68 | 69 | ```java 70 | import com.devstepbcn.wifi.AndroidWifiPackage; // <--- import 71 | 72 | public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { 73 | ...... 74 | 75 | @Override 76 | protected void onCreate(Bundle savedInstanceState) { 77 | super.onCreate(savedInstanceState); 78 | mReactRootView = new ReactRootView(this); 79 | 80 | mReactInstanceManager = ReactInstanceManager.builder() 81 | .setApplication(getApplication()) 82 | .setBundleAssetName("index.android.bundle") 83 | .setJSMainModuleName("index.android") 84 | .addPackage(new MainReactPackage()) 85 | .addPackage(new AndroidWifiPackage()) // <------ add here 86 | .setUseDeveloperSupport(BuildConfig.DEBUG) 87 | .setInitialLifecycleState(LifecycleState.RESUMED) 88 | .build(); 89 | 90 | mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null); 91 | 92 | setContentView(mReactRootView); 93 | } 94 | 95 | ...... 96 | 97 | } 98 | ``` -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @providesModule AndroidWifiModule 3 | */ 4 | 5 | 'use strict'; 6 | 7 | import { NativeModules } from 'react-native'; 8 | module.exports = NativeModules.AndroidWifiModule; 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-android-wifi", 3 | "version": "0.0.41", 4 | "description": "A react-native implementation for viewing and connecting to Wifi networks on Android devices.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "react", 11 | "react-component", 12 | "react-native", 13 | "android", 14 | "wifi", 15 | "connection" 16 | ], 17 | "author": "Ferran Reventos ", 18 | "license": "ISC", 19 | "repository": "https://github.com/devstepbcn/react-native-android-wifi", 20 | "bugs": "https://github.com/devstepbcn/react-native-android-wifi/issues", 21 | "peerDependencies": { 22 | "react-native": ">=0.13" 23 | }, 24 | "dependencies": {}, 25 | "rnpm": { 26 | "android": { 27 | "packageInstance": "new AndroidWifiPackage()" 28 | } 29 | } 30 | 31 | } 32 | --------------------------------------------------------------------------------