Referring to How to disable Mobile Data on Android , we know the approach to enable/disable data connection in Android 2.2 by java reflection.
However, in Android 2.3 and up, android.permission.MODIFY_PHONE_STATE
is no longer supported and I found the way above does not work in Android 2.3. Do you have another idea to enable data connection?
ConnectivityManager mgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
Method dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
dataMtd.setAccessible(true);
dataMtd.invoke(mgr, true/false);
you need android.permission.CHANGE_NETWORK_STATE permission too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With