Reputation: 4598
Possible Solutions here : How to disable Mobile Data on Android
In http://developer.android.com/reference/android/net/ConnectivityManager.html we see how we can query different network availability. is there a way to tell the device to not use GPRS/ other data?
Want a way to do what happens in the settings/Wireless and networks/Mobile networks when you toggle 'Use packet data'
Want API to disable the cellular one, not the WIFI. WIFI is already off. Want it to remain off. goal is to give a quicker UI to switch 'Use packet data' off and on, without changing anything else via my application which the user can keep a shortcut too or configure to switch of packet data at certain times of the day or under other conditions
Upvotes: 0
Views: 1237
Reputation: 985
If the wifi connection is established, it will get precedence over cellular networks like 2G and 3G. Once the wifi connection is broken, the android system will look for cellular connection if it is enabled and connected.
You can use the following code to disable/enable wifi adapter on the android
private void networkChangeTest() {
if(wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
} else wifiManager.setWifiEnabled(true);
}
If the wifi is enabled it will be switched off and if it is enabled, it will be switched on. When the wifi is disabled, the android system will automatically shift to cellular data connection.
Only one data connection(wifi/cellular) can be active at one time on the android system.
Update :
This link shows how to enable/disable packet(cellular) data option : How to disable Mobile Data on Android
Upvotes: 1