Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void setMobileDataEnabled(Context context, boolean enabled) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
- final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- final Class conmanClass = Class.forName(conman.getClass().getName());
- final Field connectivityManagerField = conmanClass.getDeclaredField("mService");
- connectivityManagerField.setAccessible(true);
- final Object connectivityManager = connectivityManagerField.get(conman);
- final Class connectivityManagerClass = Class.forName(connectivityManager.getClass().getName());
- final Method setMobileDataEnabledMethod = connectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
- setMobileDataEnabledMethod.setAccessible(true);
- setMobileDataEnabledMethod.invoke(connectivityManager, enabled); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement