user1285334
user1285334

Reputation: 309

Disallow use of 3g in android socket app

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?

Upvotes: 1

Views: 504

Answers (1)

sinisha
sinisha

Reputation: 1013

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;
}

Upvotes: 1

Related Questions