Skip to content

Commit e585cdb

Browse files
authored
Merge pull request #75 from Warecorp/feature/new-method-to-control-status-of-bounded-network-added
Method to get status of process forcing network added
2 parents 3b236e9 + 823438d commit e585cdb

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ Method to force wifi usage. Android by default sends all requests via mobile dat
186186
wifi.forceWifiUsage(true);
187187
```
188188

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+
189201

190202
Add a hidden wifi network and connect to it
191203
``` javascript

android/src/main/java/com/devstepbcn/wifi/AndroidWifiModule.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ public void onAvailable(Network network) {
159159
}
160160
}
161161

162+
//Use this method to make sure that your forced network already bound
163+
@ReactMethod
164+
public void connectionStatusOfBoundNetwork(Callback connectionStatusResult) {
165+
ConnectivityManager connManager = (ConnectivityManager) getReactApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
166+
Network network = connManager.getBoundNetworkForProcess();
167+
if (network != null) {
168+
connectionStatusResult.invoke(true);
169+
} else {
170+
connectionStatusResult.invoke(false);
171+
}
172+
}
173+
162174
//Method to check if wifi is enabled
163175
@ReactMethod
164176
public void isEnabled(Callback isEnabled) {

0 commit comments

Comments
 (0)