There is also a complicated way to get statistics, but this should work for all adapters: (but it is expensive, because you have to read files continously),
- Here you can see all your adapters and the sent/received data:
cat /proc/net/dev
- You can get statistics per adapter from these files:
cat /sys/class/net/**wlan0**/statistics/**rx**_bytes
wlan0 could be all of your adapters, but you need to maintain the value in your app, because if you switch off/on the adapter, the value will be 0 again. (You can have RX and TX values)
- You can get the active, currently sending/receiving app list
cat /proc/net/**tcp6**
This also can be done with tcp, tcp6, upd, upd6
Here you have the "uid" column, which is the UID of your installed apps.
(So that app is using the network right now)
From this file you can also see the connection endpoint.
- Check sent/received bytes per application (like the TrafficStats API calls)
cat /proc/uid_stat/**10348**/tcp_snd
The id here is the application UID.
You have the sent: tcp_snd and the received: tcp_rcv files too.
- You can also do some process and UID matching with:
cat /proc/**17621**/status
The id here is the process id what you can get from e.g. the top command.
In the status file you will have the UID, which is the installed/system app UID.
+1. You can take a look also on this file, TrafficStats API uses this:
cat /proc/net/xt_qtaguid/stats
Headers:
idx iface acct_tag_hex uid_tag_int cnt_set rx_bytes rx_packets tx_bytes tx_packets rx_tcp_bytes rx_tcp_packets rx_udp_bytes rx_udp_packets rx_other_bytes rx_other_packets tx_tcp_bytes tx_tcp_packets tx_udp_bytes tx_udp_packets tx_other_bytes tx_other_packets
Values:
6 eth0 0x0 10005 0 0 0 80 2 0 0 0 0 0 0 80 2 0 0 0 0
7 eth0 0x0 10005 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8 eth0 0x0 10007 0 11133 25 4751 24 11133 25 0 0 0 0 4751 24 0 0 0 0
9 eth0 0x0 10007 1 5965514 4358 102028 2327 5965514 4358 0 0 0 0 102028 2327 0 0 0 0
10 eth0 0x0 10014 0 95 1 40 1 95 1 0 0 0 0 40 1 0 0 0 0
So maybe mixing the first answer with this knowledge, you can have more and better statistics.