Try to get the data of the current application, and, surprisingly, you will notice that you can really get network information for your own application, the reason is listed below:
Prior to Android 4.3, UID traffic statistics were available for TCP and UDP and included APIs for bytes and packets, and were also sent and received. This data was extracted from the files / proc / uid _stat / [pid] / *.
In Android 4.3, the developers decided to switch to a better and more secure API using the UID xt_qtaguid statistics, which is part of the Linux netfilter kernel module. This API (procfs) allows you to access based on the UID of the process, and that is why when you try to access the TrafficStats API in Android => 4.3, you will get zero information for a non-native UID.
Thus, the current way to handle the problem may be as follows:
1) NetworkStatsManager: This involves using permission at the system level. 2) Manually read the files / proc / uid _stat /
Please note that in a later version, data is cleared at boot.
Thanks.
Pankaj meel
source share