If I go to "Settings - Data Usage" and press the "Properties" I can activate "Restrict Background Data", using a Samsung Galaxy S2 (i9105P) with Android 4.1.2.
Is there any way I can do this programmatically, both on and off?
I only want to activate/deactivate it under certain conditions (determined by my app) so I don't have to manually remember to activate it.
PS: I searched the android.developer.com website, but with no success.
As I know for Android 4.x you cant do that. Only monkey runner plugin can help you.
But if you need for Android 2.x, this is method I used:
You can run this command in the command line
svc data disable
orsvc data enable
You obviously need root to do that, like this:Runtime.getRuntime().exec("echo svc data disable | su");
This should bring up root dialog if your device is rooted.