1

I have made an Android application that sends data over networks using sockets. I'm guessing (haven't tested because I don't have an outside IP address I can use) that it works with 3G. It definitely does with WiFi.

First: If my app works with WiFi, sending data to an inside IP address, is it safe to assume that it works with 3G, if I had an outside IP-adress to send to? - Of course I'm going to test this when I get the chance.

Second: If 3G works, how would I go about making an option, for the user to not allow use of 3G, only WiFi, inside the application?

user1725145
  • 3,993
  • 2
  • 37
  • 58
user1285334
  • 309
  • 3
  • 13

1 Answers1

1

First: it is safe

Second:

private boolean checkOnlyWiFiNetworkConnection() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI")){
            if (ni.isConnected()){
                return = true;
            }
        }
    }   
    return false;
}
sinisha
  • 1,013
  • 13
  • 30
  • As far as i can tell, this piece of code just returns true/false, wether or not WiFi is enabled? If both 3G and WiFi is enabled, then will WiFi allways be used? – user1285334 Nov 02 '12 at 11:00
  • Your question wasnt clear. You should check this SO answer: http://stackoverflow.com/questions/11662978/how-to-provide-option-to-select-wi-fi-or-gprs-for-network-connectivity-in-androi – sinisha Nov 02 '12 at 11:16
  • Again, this is just enabling disabling. What i want, is to be able to make sure the socket connects over WiFi, not 3G, without turning off 3G for the phone. If you want a wifi connection, do you really have to turn 3G off? – user1285334 Nov 02 '12 at 11:31
  • It looks it's not possible to choose which network to use:http://stackoverflow.com/questions/5171770/how-to-force-the-http-connection-over-wi-fi-instead-of-cellular-in-android – sinisha Nov 02 '12 at 12:00
  • when user enabled both wifi and 3g, then 3g always be DISCONNECTED, but 3g is available? – kemdo Apr 05 '18 at 03:15