0

I have an android app that performs network connections on opening the app and disconnects and removes the networks on closing it.. If the device was initially on 3G, opening and closing the app performs the right connection/disconnection actions.

If the device was initially on WiFi, then opening the app connects to the network but closing the app disconnects from the networks and device falls back to 3G.

It should essentially fall back to the WiFi that the device was on before opening the app.. And the app doesn't disconnect/remove the WiFi that the device was on originally..

Below is a piece of sample code that performs disconnection:

            // remove the configuration (and disconnect, if connected)
            Log.i(TAG, "removing app network = " + ssid);
            boolean b = wifi.removeNetwork(wc.networkId);
            assert (b);

           // Enable the original WiFi that the device 
            String deviceInitialSSID = "TEST_WLAN";  
            previousNetId = wc.networkId;

            wifi.setWifiEnabled(true);
            wifi.enableNetwork(previousNetId, true);

The above code is executed in onStop() of the app. The calls to enable the network return true but it does not enable the previous WiFi on the device, in real.

Please advice. Thanks in advance..

Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
user591410
  • 3,051
  • 5
  • 21
  • 30
  • Seems simple enough- when you try to turn on wifi, check if it's already on. Save that value. When you attempt to turn it off, check that value. If it was true, don't turn off wifi. – Gabe Sechan Feb 26 '13 at 22:12
  • If I understand it correctly, by saving the WiFi value, you mean netId? Iam saving the SSID of the WiFi (if the device is already on WiFi) when I start and am connecting back to it when I stop the app (look at the second part of the code). I am not turning off the WiFi anywhere. Let me know if am missing something.. – user591410 Feb 26 '13 at 22:33

0 Answers0