Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
#7 - If the SSID is empty or unknown, just return false because why o…
Browse files Browse the repository at this point in the history
…n earth would we assign it a blank MAC address....

- Implemented the function 'getConnectedBSSID' for Android since it was missing
  • Loading branch information
Nicholas Clancy committed Mar 20, 2018
1 parent a6744d0 commit 3deb50f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
Binary file modified .vs/slnx.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

##### Latest Stable Release: v2.3.0

##### Latest Dev Release: v2.3.3 (20/03/2018)
##### Latest Dev Release: v2.3.4 (20/03/2018)



Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordovanetworkmanager",
"version": "2.3.3",
"version": "2.3.4",
"cordova": {
"id": "cordovanetworkmanager",
"platforms": [
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordovanetworkmanager"
version="2.3.3">
version="2.3.4">

<name>cordovaNetworkManager</name>
<description>Cordova Network Manager for Android and iOS</description>
Expand Down
34 changes: 30 additions & 4 deletions src/android/cordovanetworkmanager/cordovaNetworkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class cordovaNetworkManager extends CordovaPlugin {
private static final String IS_WIFI_ENABLED = "isWifiEnabled";
private static final String SET_WIFI_ENABLED = "setWifiEnabled";
private static final String TAG = "cordovaNetworkManager";
private static final String GET_CONNECTED_BSSID = "getConnectedBSSID";

private WifiManager wifiManager;
private CallbackContext callbackContext;
Expand Down Expand Up @@ -109,6 +110,9 @@ else if(action.equals(DISCONNECT)) {
else if(action.equals(GET_CONNECTED_SSID)) {
return this.getConnectedSSID(callbackContext);
}
else if(action.equals(GET_CONNECTED_BSSID)){
return this.getConnectedBSSID(callbackContext);
}
else {
callbackContext.error("Incorrect action parameter: " + action);
}
Expand Down Expand Up @@ -502,18 +506,40 @@ private boolean getConnectedSSID(CallbackContext callbackContext){
}

String ssid = info.getSSID();
if(ssid.isEmpty() || ssid == "<unknown ssid>") {
ssid = info.getBSSID();
}
if(ssid.isEmpty() || ssid == "<unknown ssid>"){
callbackContext.error("SSID is empty");
callbackContext.error("SSID is empty or unknown");
return false;
}

callbackContext.success(ssid);
return true;
}

/**
* This method retrieves the BSSID for the currently connected network
*
* @param callbackContext A Cordova callback context
* @return true if BSSID found, false if null or empty.
*/
private boolean getConnectedBSSID(CallbackContext callbackContext){
if(!wifiManager.isWifiEnabled()){
callbackContext.error("Wifi is disabled");
return false;
}

WifiInfo info = wifiManager.getConnectionInfo();

String bssid = info.getBSSID();

if(bssid.isEmpty() || bssid == null){
callbackContext.error("BSSID is empty or unknown");
return false;
}

callbackContext.success(bssid);
return true;
}

/**
* This method retrieves the current WiFi status
*
Expand Down

0 comments on commit 3deb50f

Please sign in to comment.