Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ICS is it possible to set the "Restrict background data" setting from code (programmatically)?

In ICS there is now the "Restrict background data" setting in the Network -> Data usage settings screens.

Is there a way to programmatically set "Restrict background data" for my application?

OR

Is there a way to bring up the "Data usage" settings that has the option for my application?

like image 671
pzulw Avatar asked Mar 14 '12 17:03

pzulw


1 Answers

You can start from the Overview of Data Usage Android Tech Info page.

Each network device driver will report its usage statsitics to xt_qtaguid module in the android-3.0 Linux kernel. Then, from the framework you can specify additional rules to restrict background data traffic for an application.

Try providing counterSet and UID params to com.android.server.NetworkManagementSocketTagger setKernelCounterSet() method. Where counterSet values are defined in android.net.NetworkPolicyManager and UID would be your application id obtained through ContextWrapper.getApplicationInfo().uid.

I hope this gets you started.

like image 85
dobridog Avatar answered Nov 11 '22 03:11

dobridog