TrafficStats.getUidRxBytes(uid)
gets the traffic of an app. But, I do not know which UID is the WiFi hotspot (which is a system app).
AID_WIFI
's UID is 1010
, so I have tried TrafficStats.getUidRxBytes(1010)
when the WiFi hotspot is opened and another phone connect is connected to it (and searching retrieving some pictures from the Internet), but it just return -1
.
If I run:
int uid = 1010;
long rx = TrafficStats.getUidRxBytes(uid);
sb.append("接受mobile:" + rx);
long tx = TrafficStats.getUidTxBytes(uid);
sb.append("发送mobile:" + rx);
long rx1 = TrafficStats.getUidRxPackets(uid);
sb.append("接受wifi:" + rx1);
long tx1 = TrafficStats.getUidTxPackets(uid);
sb.append("发送wifi:" + tx1);
Log.e("test111",sb.toString());
The console log output is:
接受mobile:-1
发送mobile:-1
接受wifi:-1
发送wifi:-1