networking - Android network not reconnecting when Wifi drops -


is there reason why wifi network set on android (lollipop) wouldn't automatically reconnect after router reset? network being set this:

private boolean connecttonetwork(scanresult scanresult, string password, wifimanager wifimanager) {     wificonfiguration wificonfig = new wificonfiguration();     string quotedssid = "\"" + scanresult.ssid + "\"";     wificonfig.ssid = quotedssid;     wificonfig.status = wificonfiguration.status.disabled;     wificonfig.priority = 40;      // dependent on security type of selected network     // set security settings configuration     securitytype securitytype = getsecuritytype(scanresult);     if (securitytype == securitytype.open)     {         // no security         wificonfig.allowedkeymanagement.set(wificonfiguration.keymgmt.none);         wificonfig.allowedprotocols.set(wificonfiguration.protocol.rsn);         wificonfig.allowedprotocols.set(wificonfiguration.protocol.wpa);         wificonfig.allowedauthalgorithms.clear();         wificonfig.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.ccmp);         wificonfig.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.tkip);         wificonfig.allowedgroupciphers.set(wificonfiguration.groupcipher.wep40);         wificonfig.allowedgroupciphers.set(wificonfiguration.groupcipher.wep104);         wificonfig.allowedgroupciphers.set(wificonfiguration.groupcipher.ccmp);         wificonfig.allowedgroupciphers.set(wificonfiguration.groupcipher.tkip);     }     else if (securitytype == securitytype.wpa)     {         //wpa/wpa2 security         wificonfig.allowedprotocols.set(wificonfiguration.protocol.rsn);         wificonfig.allowedprotocols.set(wificonfiguration.protocol.wpa);         wificonfig.allowedkeymanagement.set(wificonfiguration.keymgmt.wpa_psk);         wificonfig.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.ccmp);         wificonfig.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.tkip);         wificonfig.allowedgroupciphers.set(wificonfiguration.groupcipher.wep40);         wificonfig.allowedgroupciphers.set(wificonfiguration.groupcipher.wep104);         wificonfig.allowedgroupciphers.set(wificonfiguration.groupcipher.ccmp);         wificonfig.allowedgroupciphers.set(wificonfiguration.groupcipher.tkip);         wificonfig.presharedkey = "\"".concat(password).concat("\"");     }     else if (securitytype == securitytype.wep)     {         // wep security         wificonfig.allowedkeymanagement.set(wificonfiguration.keymgmt.none);         wificonfig.allowedprotocols.set(wificonfiguration.protocol.rsn);         wificonfig.allowedprotocols.set(wificonfiguration.protocol.wpa);         wificonfig.allowedauthalgorithms.set(wificonfiguration.authalgorithm.open);         wificonfig.allowedauthalgorithms.set(wificonfiguration.authalgorithm.shared);         wificonfig.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.ccmp);         wificonfig.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.tkip);         wificonfig.allowedgroupciphers.set(wificonfiguration.groupcipher.wep40);         wificonfig.allowedgroupciphers.set(wificonfiguration.groupcipher.wep104);          if (gethexkey(password))             wificonfig.wepkeys[0] = password;         else             wificonfig.wepkeys[0] = "\"".concat(password).concat("\"");         wificonfig.weptxkeyindex = 0;     }      // add new configuration managed list of networks     connectionreceiver = new connectionreceiver();     intentfilter intentfilter = new intentfilter();     intentfilter.addaction(wifimanager.supplicant_state_changed_action);     intentfilter.addaction(connectivitymanager.connectivity_action);     registerreceiver(connectionreceiver, intentfilter);     int networkid = wifimanager.addnetwork(wificonfig);     if (networkid != -1)     {         if(wifimanager.enablenetwork(networkid, true))         {             wifimanager.saveconfiguration();             return true;         }     }      // connection failed     unregisterreceiver(connectionreceiver);     connectionreceiver = null;      return false; } 

which works fine , connects network. network continue work fine until switch off wifi router. then, after switching on , waiting device reconnect, errors , can't access internet. following code returns true, looks device has reconnected network:

public boolean isnetworkavailable() {     connectivitymanager connectivitymanager = (connectivitymanager) getsystemservice(context.connectivity_service);     networkinfo activenetworkinfo = connectivitymanager.getactivenetworkinfo();     return activenetworkinfo != null && activenetworkinfo.isconnected(); } 

the active network in above if correct wifi network, when trying access anything, errors. example, chromium gives bunch of:

e/chromium: [error:socket_posix.cc(80)] createplatformsocket() returned error, errno=64: machine not on network w/chromium: [warning:net_errors_posix.cc(116)] unknown error 64 mapped net::err_failed 

and volley gives same:

java.net.socketexception: socket failed: errno 64 (machine not on network) 

turns out code setting process default network elsewhere:

connectivitymanager.setprocessdefaultnetwork(net);

removing line fixed issue.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -