I'm trying to get the traffic generated by my application. It includes a video streaming and I want to get network usage data.
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:
int uid = getApplication().getApplicationInfo().uid;
uid = android.os.Process.myUid();
long txApp = TrafficStats.getUidTxBytes(uid);
long rxApp = TrafficStats.getUidRxBytes(uid);
With both uids I get an error (-1) on TrafficStats. Any help?