hoerresb / WifiWizard

A Cordova plugin for managing Wifi networks
Apache License 2.0
205 stars 177 forks source link

setWifiEnabled always calls fail cb #79

Open podema opened 8 years ago

podema commented 8 years ago

Hi! I am trying to enable WiFi if disabled. I can succesfully check the state, and if enabled and connected can dissconnect from the current AP. However any cal to setWifiEnabled fails. Using Android 5.0.2, Cordova 6.1.1 and WifiWizard 0.2.11, here's the code used:

if(typeof WifiWizard != 'undefined'){
  if(WifiWizard.isWifiEnabled(function(result){
    if(result){
      //wifi is connected
      console.log("wifi already enabled");
      console.log("disconnecting...");
      WifiWizard.getCurrentSSID(
          function(ssid){
            WifiWizard.disconnectNetwork(ssid,
                function(){console.log("ok")},
                function(){console.log("failed!")}
                )
          }, 
          function(fail){
            //error message for isWifiEnabled
            console.log("cannot get current ssid");
          }
          );

    }else{
      WifiWizard.setWifiEnabled(true,
          function(results){
            if(results == 'OK'){
              //enabled wifi
              console.log("wifi enabled");
            }
          },
          function(fail){
            //error message for setWifiEnabled
            console.log(fail);
          }
          );
    }

  },function(fail){
    //error message for isWifiEnabled
    console.log(fail);
  }));
}

wich outputs the following: Cannot enable wifi

I checked the source code and seems that it fails on wifiManager.setWifiEnabled(status.equals("true")) I checked the permissions on android manifest and everything seems fine Also here's the filtered logcat out:

W/CordovaPlugin( 4024): Attempted to send a second callback for ID: WifiWizard1939867177
W/CordovaPlugin( 4024): Result was: "Invalid action"
I/chromium( 4024): [INFO:CONSOLE(1)] "Cannot enable wifi", source:  (1)

I tried with both wifi enabled and disabled, enabling and disabling the wifi. nothing works, i'm maybe getting something wrong. So i'll be glad if someone helps. Thanks in advance!

podema commented 8 years ago

After a little research it seems that the issue is with my smartphone. I tried with a another couple of smartphones and it works flawlessy. You can always open a dialog to tell the user that it must manually open the wifi. Close the bug. Sorry for any inconvenience