title: How to enable mobile data on/off programmatically
body: <p>In android how to enable mobile data on and off in android 4.4 and above versions.
  I have used this code but it is not working in android 4.4 and above versions:</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>