title: Enable/Disable Mobile Data (GPRS) using code without disconnecting adb
body: <p>I have to enable/disable data in the same usecase, that i used code given here <a href="https://stackoverflow.com/questions/3644144/how-to-disable-mobile-data-on-android">How to disable Mobile Data on Android</a></p>
  
  <pre><code>private void setMobileDataEnabled(Context context, boolean enabled) {
  final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
  final Class conmanClass = Class.forName(conman.getClass().getName());
  final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService");
  iConnectivityManagerField.setAccessible(true);
  final Object iConnectivityManager = iConnectivityManagerField.get(conman);
  final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName());
  final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
  setMobileDataEnabledMethod.setAccessible(true);
  
  setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled);
  </code></pre>
  
  <p>}</p>
  
  <p>but problem is that when i am passing false it is disconnecting with adb.
  can we disable data without disconnecting adb</p>
  
  <p>Adding logcat when passing false</p>
  
  <pre><code>12-10 12:18:20.261: D/ConnectivityService(150): setMobileDataEnabled(false)
  12-10 12:18:20.321: W/BackupManagerService(150): dataChanged but no participant             pkg='com.android.providers.settings' uid=1001
  12-10 12:18:20.681: D/ConnectivityService(150): ConnectivityChange for mobile: DISCONNECTED/DISCONNECTED
  12-10 12:18:20.691: D/ConnectivityService(150): Attempting to switch to wifi
  12-10 12:18:20.811: D/dalvikvm(233): GC_CONCURRENT freed 505K, 7% free 8848K/9479K, paused 91ms+112ms, total 443ms
  12-10 12:18:20.821: D/ConnectivityService(150): resetConnections(eth0, 3)
  12-10 12:18:20.821: D/NetUtils(150): android_net_utils_resetConnections in  env=0x2a13bfc8 clazz=0x7be00001 iface=eth0 mask=0x3
  : E/(): Device disconnected
  </code></pre>