title: Trafficstats from specific application
body: <p>I'm trying to get the traffic generated by my application. It includes a video streaming and I want to get network usage data.</p>
  
  <p>I've used TrafficStats with Mobile and Total function. Now I want to set it to work using the application UID but I haven't managed to do so, as it always returns -1. I'm using Android 2.3.4 and here is the code:</p>
  
  <pre><code>int uid = getApplication().getApplicationInfo().uid;
  uid = android.os.Process.myUid();
  long txApp = TrafficStats.getUidTxBytes(uid);
  long rxApp = TrafficStats.getUidRxBytes(uid);
  </code></pre>
  
  <p>With both uids I get an error (-1) on TrafficStats. Any help?</p>