Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getCurrentBSSID now available on android. #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/android/src/com/pylonproducts/wifiwizard/WifiWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class WifiWizard extends CordovaPlugin {
private static final String START_SCAN = "startScan";
private static final String GET_SCAN_RESULTS = "getScanResults";
private static final String GET_CONNECTED_SSID = "getConnectedSSID";
private static final String GET_CONNECTED_BSSID = "getConnectedBSSID";
private static final String IS_WIFI_ENABLED = "isWifiEnabled";
private static final String SET_WIFI_ENABLED = "setWifiEnabled";
private static final String TAG = "WifiWizard";
Expand Down Expand Up @@ -99,6 +100,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 @@ -491,6 +495,36 @@ private boolean getConnectedSSID(CallbackContext callbackContext){
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 not.
*/
private boolean getConnectedBSSID(CallbackContext callbackContext){
if(!wifiManager.isWifiEnabled()){
callbackContext.error("Wifi is disabled");
return false;
}

WifiInfo info = wifiManager.getConnectionInfo();

if(info == null){
callbackContext.error("Unable to read wifi info");
return false;
}

String bssid = info.getBSSID();

if(bssid.isEmpty()){
callbackContext.error("BSSID is empty");
return false;
}

callbackContext.success(bssid);
return true;
}

/**
* This method retrieves the current WiFi status
*
Expand Down
4 changes: 2 additions & 2 deletions www/WifiWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ var WifiWizard = {
}
cordova.exec(win, fail, 'WifiWizard', 'getConnectedSSID', []);
},

getCurrentBSSID: function(win, fail) {
if (typeof win != "function") {
console.log("getCurrentSSID first parameter must be a function to handle SSID.");
console.log("getCurrentSSID first parameter must be a function to handle BSSID.");
return;
}
cordova.exec(win, fail, 'WifiWizard', 'getConnectedBSSID', []);
Expand Down