Android: How to Enable/Disable Wifi or Internet Connection Programmatically
<p>Using the Connectivity Manager Class we can get access to either wifi or Internet Network:  </p>

<pre><code>ConnectivityManager connec = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

// ARE WE CONNECTED TO THE NET
if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
  connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED ) {
  // ...
}
</code></pre>

<p>where <code>0</code> and <code>1</code> respectively refers to mobile and wifi connection</p>

<p>If my Android device is connected to both, can we switch between any of the network or can we disable any of the network? Like using a function:</p>

<pre><code>connec.getNetworkInfo(0).setState(NetworkInfo.State.DISCONNECTED);
</code></pre>
