Issue
I'm developing an android app with a capability of connecting to WiFi Networks through it, and everything is OK, I'm creating available WiFi Nets list and the user user one of them to establish connectivity, the following method is the one which is used to establish that connectivity :
int netId;
boolean disableOthers;
wifiManager.enableNetwork(netId, disableOthers);
now I've Two scenarios:
- The first one is to set
disableOthers
totrue
and that will disable the the connected Network in order to establish a connection with the mentioned one. - The second one is to set
disableOthers
tofalse
and that will NOT disable the the connected Network and thus the new Network Connection will not be established as there's already a successfully established connection exists.
So, I don't have any options but using case one, but the problem is upon disabling the connected network, if the connection to the new Network fails due to any reason like wrong password or out of range, the device becomes without any Net connection established, So, all I want is a way enables me to regain the previous connection when the aiming to connect to a new one fails.
UPDATE:
Regarding to @bmartins answer, I did the tip the following way :
public static int net_id;
// storing the current connection Net.ID
WifiInfo info = wifiManager.getConnectionInfo();
net_id = info.getNetworkId();
// connecting to the new Net
private void connect(networkId){
wifiManager.disconnect();
wifiManager.enableNetwork(networkId, true);
wifiManager.reconnect();
wifiManager.saveConfiguration();
}
And then when the connection fails:
connect(net_id);
Solution
Sounds like a logical issue.
Why not keep track of the last successful netId? If new fails ->
wifiManager.enableNetwork(lastGoodNetId, true);
Answered By - ehanoc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.