Here you can find the source of setMobileDataEnabled(Activity a, Context context, boolean enabled)
@SuppressWarnings({ "rawtypes", "unchecked" }) private static void setMobileDataEnabled(Activity a, Context context, boolean enabled)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; public class Main { @SuppressWarnings({ "rawtypes", "unchecked" }) private static void setMobileDataEnabled(Activity a, Context context, boolean enabled) { final ConnectivityManager conman = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); Class conmanClass = null; try {//from w w w .ja v a2 s . c o m conmanClass = Class.forName(conman.getClass().getName()); } catch (ClassNotFoundException e) { } Field iConnectivityManagerField = null; try { iConnectivityManagerField = conmanClass .getDeclaredField("mService"); } catch (SecurityException e) { } catch (NoSuchFieldException e) { } iConnectivityManagerField.setAccessible(true); Object iConnectivityManager = null; try { iConnectivityManager = iConnectivityManagerField.get(conman); } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } Class iConnectivityManagerClass = null; try { iConnectivityManagerClass = Class.forName(iConnectivityManager .getClass().getName()); } catch (ClassNotFoundException e) { } Method setMobileDataEnabledMethod = null; try { setMobileDataEnabledMethod = iConnectivityManagerClass .getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE); } catch (SecurityException e) { } catch (NoSuchMethodException e) { } setMobileDataEnabledMethod.setAccessible(true); try { setMobileDataEnabledMethod .invoke(iConnectivityManager, enabled); } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } }