-
Notifications
You must be signed in to change notification settings - Fork 177
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
isWifiEnabled doesnt properly reflect the state of the wifi #6
Comments
Thanks for reporting the issue! Could you let me know which version you were using? If it's not a known issue already I'll add it. |
Thanks for the reply! |
I think the problem is somehow related to the way setWifiEnabled works. |
Interesting. I don't know offhand but I'll look into it. @brugnara, could you comment on this behavior? You're more familiar with the code on this feature than I am. |
I can confirm the behavior. If I run WifiWizard.addNetwork within a WifiWizard.setWifiEnabled success handler, I get timing issues due to the unclear state during wifi enabling phase.
right now I have added a timeout between setting wifi to enabled and adding a wifi network, but that's merely a hacky fix of course. |
WifiWizard.setWifiEnabled("true", function (result) {
console.log("enabling Wifi");
console.log(result);
var nfcwificonfig = WifiWizard.formatWPAConfig(WifiWizard.formatWifiString(SSID), Password);
WifiWizard.isWifiEnabled(function(wifienabled) {
console.log(wifienabled);
});
//$timeout(function() {
WifiWizard.addNetwork(nfcwificonfig, function(result) {
console.log("addNetwork success. message from Plugin: " + result);
WifiWizard.connectNetwork(SSID, function() {
console.log("connectNetwork success. message from Plugin: " + result);
});
}, function (error) {
console.log("error adding network: " + error);
});
//}, 2000);
}); yields
What's really confusing me is the fact that WiFiWizard.isWiFiEnabled still yields true even though WiFiWizard.addNetwork is telling me that the WiFi is not enabled. From what I can see in your java plugin code both should depend on the value of WiFiManager.isWifiEnabled () apparently there is a related post on stackoverflow. |
Good call. It seems that |
Android API is involved here and the behaviour of That part of code is very simple: private boolean isWifiEnabled(CallbackContext callbackContext) {
boolean isEnabled = wifiManager.isWifiEnabled();
callbackContext.success(isEnabled ? "1" : "0");
return isEnabled;
} And Android API says about isWifiEnabled:
|
@parsonsmatt Waiting for status change sounds very bad for me. As I wrote, this is not a framework :) |
I'd also agree with @brugnara on the framework question What you do in Java is: if(action.equals(IS_WIFI_ENABLED)) {
return this.isWifiEnabled(callbackContext);
} else if(action.equals(SET_WIFI_ENABLED)) {
return this.setWifiEnabled(callbackContext, data);
} else if (!wifiManager.isWifiEnabled()) {
callbackContext.error("Wifi is not enabled.");
return false;
} else if(action.equals(ADD_NETWORK)) {
return this.addNetwork(callbackContext, data);
} else if(action.equals(REMOVE_NETWORK)) {
[...] A thing that I unfortunately don't know is if Android allows the addition of networks if the state is still on "WIFI_STATE_ENABLING". I also agree that the phonegap plugin should be modeled after native android behavior, but in case that android does allow adding and removal of networks during ENABLING phase, then the current implementation does not reflect this properly. |
Yesterday i got the latest version of WifiWizard Plugin for my Cordova/Phonegap Project via "cordova plugin add com.pylonproducts.wifiwizard". Everything works fine except the WifiWizard.isWifiEnabled, it always return True even when the Wifi is not enabled.
|
Thanks for bringing this up. I will take a look at the issue and hopefully have a fix in the next couple of days. |
isWifiEnabled is only set after the status of the wifi is retrieved, if I use addnetwork without first checking the active wifi connection it will incorrectly give me the information that wifi is not enabled
EDIT: never mind I found the fix. apparently I was using an older version of the plugin
The text was updated successfully, but these errors were encountered: