title: How do I programmatically show data usage of all applications?
body: <p>On Android 4.0 onwards we have data usage control options in the phone. Please check the attached screen shot for further understanding.</p>
  
  <p><a href="http://developer.android.com/about/versions/android-4.0-highlights.html" rel="noreferrer">http://developer.android.com/about/versions/android-4.0-highlights.html</a></p>
  
  <p>Now I have some requirement to check these things (All Application's Data usage in specific time period/specific days) from my application. How can I achieve this? I am also using the below class for Network Usage details.</p>
  
  <p><a href="http://developer.oesf.biz/em/developer/reference/eggplant/android/net/NetworkStatsHistory.html" rel="noreferrer">http://developer.oesf.biz/em/developer/reference/eggplant/android/net/NetworkStatsHistory.html</a></p>
  
  <p>Please check the below link images. I need to develop the same kind of application.</p>
  
  <ul>
  <li><p><a href="http://developer.android.com/sdk/images/4.0/usage-all-lg.png" rel="noreferrer">http://developer.android.com/sdk/images/4.0/usage-all-lg.png</a></p></li>
  <li><p><a href="http://developer.android.com/sdk/images/4.0/usage-maps-lg.png" rel="noreferrer">http://developer.android.com/sdk/images/4.0/usage-maps-lg.png</a></p></li>
  </ul>
  
  <p>Thanks for sharing your code, but I need to know data used by each application instead of all applications. So far I observed in the links no one is talking about data usage of individual applications. I already know how to show installed applications in the device. Now I would like to know what's the data used by each and every application.</p>
  
  <p>I am using the below code for list of installed applications in the device.</p>
  
  <pre><code>private ArrayList&lt;PInfo&gt; getInstalledApps(boolean getSysPackages) {
      ArrayList&lt;PInfo&gt; res = new ArrayList&lt;PInfo&gt;();
  
      List&lt;PackageInfo&gt; packs = getPackageManager().getInstalledPackages(0);
  
      for (int i=0; i&lt;packs.size(); i++) {
          PackageInfo p = packs.get(i);
          if ((!getSysPackages) &amp;&amp; (p.versionName == null)) {
              continue ;
          }
          PInfo newInfo = new PInfo();
          newInfo.setAppname(p.applicationInfo.loadLabel(getPackageManager()).toString());
          newInfo.setPname(p.packageName);
          newInfo.setVersionName(p.versionName);
          newInfo.setVersionCode(p.versionCode);
          newInfo.setIcon(p.applicationInfo.loadIcon(getPackageManager()));
  
          res.add(newInfo);
      }
      return res;
  }
  </code></pre>
  
  <p>How do I know what's the data used by each application?</p>
  
  <p>Actually, I need a solution which gives data usage of applications in a given time period, i.e. in between two days.</p>