Last active
September 4, 2018 10:30
-
-
Save alximw/32b99f8d9e54229af86344fec405d3d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void setMobileDataEnabled(boolean mobileDataEnabled) { | |
| try { | |
| Object connectivityManager = this.ctx.getSystemService("connectivity"); | |
| Field mServiceField = Class.forName(connectivityManager.getClass().getName()).getDeclaredField("mService"); | |
| mServiceField.setAccessible(true); | |
| connectivityManager = mServiceField.get(connectivityManager); | |
| Method setMobileDataEnabledMethod = Class.forName(connectivityManager.getClass().getName()).getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE); | |
| setMobileDataEnabledMethod.setAccessible(true); | |
| setMobileDataEnabledMethod.invoke(connectivityManager, Boolean.valueOf(mobileDataEnabled)); | |
| } | |
| catch(Exception ex) { | |
| ex.printStackTrace(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment