I am trying to get traffic generated by my application. It includes streaming video, and I want to get network usage data.
I used TrafficStats with Mobile and Total. Now I want to configure it to work using the application UID, but I did not succeed, since it always returns -1. I am 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?
source share