0

I have a list of apps which consume high battery. when I select one app, I want to "Restrict background data (Settings > Data usage > select app > Restrict background data)" for the selected app. How Can I do this ?

Same question is asked at below link Programatically toggle "Restrict Background Data"

And it says it can not be done.

Community
  • 1
  • 1
Sunita
  • 1,219
  • 12
  • 16

3 Answers3

1

You can run this command in the command line svc data disable or svc 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.

pelya
  • 4,326
  • 2
  • 24
  • 23
  • Already rooted and this Exception occurs. java.io.IOException: Error running exec(). Command: [echo, svc, data, disable, |, su] Working Directory: null Environment: null – Myat Min Soe May 06 '15 at 13:11
  • Try "/system/bin/sh -c \"echo svc data disable | su\"", or better put all parameters in a string array. – pelya May 07 '15 at 11:34
0

And it says it can not be done.

There is nothing in the Android SDK for this. Therefore, it is usually assumed to be impossible until proven otherwise. In this case, there is also a security aspect -- one app should not be able to control this setting for other apps, except perhaps on rooted devices.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I am able to launch Data usage Activity of Settings Screen. I am trying to launch Data usage activity for selected application, which also shows "Restrict background data" option. I checked source code also for this. AppDetailsFragment$ show(DataUsageSummary parent, AppItem app, CharSequence label) method of DataUsageSummary.java is keyMethod. But I think its not correct to use this method and passing these arguments is also not easy. So is there any other way to achieve my goal? – Sunita May 12 '14 at 19:51
  • 1
    @Clara: I know of nothing in the Android SDK for what you seek. – CommonsWare May 12 '14 at 20:08
  • @Clara were you able to solve this, I am also looking for similar problem and want to go to Data usage activity for selected application, after that I am planning to direct to user with the help of a toast for what has to be done. Please help. – dirtydexter Jun 04 '14 at 07:40
  • @dirtydexter I have posted some code block.Please check if it helps to solve your problem. – Sunita Jun 04 '14 at 19:27
  • @dirtydexter I deleted the code as it will not work without some libraries. – Sunita Jun 04 '14 at 20:43
  • @Clara Libraries is okay, just that it is very important for the application I am developing so if you could post that code that works with some library it will be very helpful, thanks. – dirtydexter Jun 05 '14 at 04:06
0

You may try Reflection.I am not sure of it.

Sunita
  • 1,219
  • 12
  • 16
  • There is no `NetworkPolicyManager` in the Android SDK. – CommonsWare Jun 04 '14 at 19:37
  • @CommonsWare.Yes you are right.I updated my answer.It needs "framework_intermediates.jar", which can only be accessed if anyone has full android source code built.Thanks. – Sunita Jun 04 '14 at 20:10