diff --git a/src/android/src/com/pylonproducts/wifiwizard/WifiWizard.java b/src/android/src/com/pylonproducts/wifiwizard/WifiWizard.java index 2c4ac8f..6ba7de4 100644 --- a/src/android/src/com/pylonproducts/wifiwizard/WifiWizard.java +++ b/src/android/src/com/pylonproducts/wifiwizard/WifiWizard.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -487,10 +487,43 @@ private boolean getConnectedSSID(CallbackContext callbackContext){ return false; } + // http://developer.android.com/intl/zh-cn/reference/android/net/wifi/WifiInfo.html#getSSID() + if(ssid.startsWith("\"") && ssid.endsWith("\"")){ + ssid = ssid.substring(1, ssid.length()-1); + } 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 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 * @@ -531,9 +564,9 @@ private boolean setWifiEnabled(CallbackContext callbackContext, JSONArray data) Log.d(TAG, "WifiWizard: disconnectNetwork invalid data"); return false; } - + String status = ""; - + try { status = data.getString(0); } @@ -542,11 +575,11 @@ private boolean setWifiEnabled(CallbackContext callbackContext, JSONArray data) Log.d(TAG, e.getMessage()); return false; } - + if (wifiManager.setWifiEnabled(status.equals("true"))) { callbackContext.success(); return true; - } + } else { callbackContext.error("Cannot enable wifi"); return false;