(Cordova / Phonegap) Problems with WifiManager.addNetwork() method of Android -


currently writing app in cordova 3.4.0 should import wifi settings source, file or database.

if use wifimanager.addnetwork method of android, always returns -1 "failed".

on other hand: if use same code in oncreate() method of blank activity, settings added , return id of new entry.

the app developed api 10 19 , call cordova code from plugin context.

the android app has following permissions:

<uses-permission android:name="android.permission.access_wifi_state" /> <uses-permission android:name="android.permission.change_wifi_state" /> 

my test device: samsung galaxy y (gt-s5360) android 2.3.6.

is bug or feature? there seems no details in logcat e.g. tells more.

if @ official android code, see hint external iwifimanager service seems device specific.

here code:

private void addwifisettings() {     string ssid = "my_network";     string pwd = "my_secrect_password";      context ctx = this.cordova.getactivity().getapplicationcontext();     // in blank activity project is:     //      // ctx = this.getapplicationcontext();      wifimanager man = (wifimanager)ctx.getsystemservice(context.wifi_service);      wificonfiguration wc = new wificonfiguration();      wc.status = wificonfiguration.status.enabled;     wc.priority = 1;     wc.networkid = -1;     wc.hiddenssid = false;      // ssid , password     wc.ssid = "\"".concat(ssid).concat("\"");     wc.presharedkey = "\"".concat(pwd).concat("\"");      wc.allowedprotocols.clear();     wc.allowedprotocols.set(wificonfiguration.protocol.rsn);     wc.allowedprotocols.set(wificonfiguration.protocol.wpa);      wc.allowedkeymanagement.clear();     wc.allowedkeymanagement.set(wificonfiguration.keymgmt.wpa_psk);      wc.allowedpairwiseciphers.clear();     wc.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.ccmp);     wc.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.tkip);      wc.allowedgroupciphers.clear();     wc.allowedgroupciphers.set(wificonfiguration.groupcipher.wep40);     wc.allowedgroupciphers.set(wificonfiguration.groupcipher.wep104);     wc.allowedgroupciphers.set(wificonfiguration.groupcipher.ccmp);     wc.allowedgroupciphers.set(wificonfiguration.groupcipher.tkip);      wc.allowedauthalgorithms.clear();     wc.allowedauthalgorithms.set(wificonfiguration.authalgorithm.open);      string wifiaction;     int netid;     if (wc.networkid < 0) {         // if network new          wifiaction = "add";         netid = man.addnetwork(wc);     }     else {         // if network exists , should updated          wifiaction = "update";         netid = man.updatenetwork(wc);     }      // !!! @ point returns -1 in cordova/phonegap project !!!     if (netid < 0) {         throw new exception(string.format("could not %s network: %s",                                           wifiaction,                                           wc.ssid));     }      if (man.saveconfiguration() == false) {         throw new exception("could not save network configuration!");     }      man.enablenetwork(netid, false); } 

networkid ignored, don't need set it.

i wrote working cordova plugin interfaces wifimanager. abbreviated relevant code wpa:

wifi.ssid = newssid; wifi.presharedkey = newpass; wifi.status = wificonfiguration.status.enabled;         wifi.allowedgroupciphers.set(wificonfiguration.groupcipher.tkip); wifi.allowedgroupciphers.set(wificonfiguration.groupcipher.ccmp); wifi.allowedkeymanagement.set(wificonfiguration.keymgmt.wpa_psk); wifi.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.tkip); wifi.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.ccmp); wifi.allowedprotocols.set(wificonfiguration.protocol.rsn); wifimanager.addnetwork(wifi); wifimanager.saveconfiguration(); 

that should started in figuring out why code isn't working. i'd guess you're trying wificonfiguation object , need pare down somewhat. looks you're trying set wc accept wep or wpa network.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -