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

Master #59

Closed
wants to merge 2 commits into from
Closed
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
43 changes: 38 additions & 5 deletions src/android/src/com/pylonproducts/wifiwizard/WifiWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down