How to obtain amount of transferred data through Wi-Fi from other applications?

廉价感情. 提交于 2019-12-14 03:54:50

问题


I'm facing to this problem. I spent much time by searching some API or "something" with it's possible to obtain transferred data through Wi-Fi from other applications (how screenshot bellow shows).

Does someone know a way how to do it? Is here someone who tried (or has already done) for something similar? Or a little differently: Is this possible to do it?

Currently i think that this is not possible because i think that non-system application cannot retrieve data from other application(s) installed on device. But maybe i can "missing" something so i placed this question and will be glad for whatever suggestion.

Thanks in advance!


回答1:


TrafficStats

Class that provides network traffic statistics. These statistics include bytes transmitted and received and network packets transmitted and received, over all interfaces, over the mobile interface, and on a per-UID basis.

This means you can use getUidTxBytes to get whole transmitted data and so far getUidRxBytes to get whole received data.

And you can get application's UID with:

getApplicationInfo().uid 

or for other applications refer THIS




回答2:


While Sercan's answer is correct, must warn you that TrafficStats is not always guaranteed to give you correct stats. Basically TrafficStats will check files in the directory /proc/uid_stat/1094/ and various files like tcp_snd, tcp_rcv etc under this directory. On some devices, these (pseudo)files are not updated. Hence you should always check for a return value of UNSUPPORTED (-1) http://developer.android.com/reference/android/net/TrafficStats.html#UNSUPPORTED

Also, typically these stats have not been including UDP data. So the numbers you report will be wrong for apps that use UDP (like VoIP apps). For more details, look at https://code.google.com/p/android/issues/detail?id=32410

On latest Android versions, there is another /proc file that gives you a lot of details. This is at /proc/self/net/xt_qtaguid/stats. But this pseudo file will only show the stats of an app reading that. Any Android app tries to read this file, it will not get stats related to any other Android app.




回答3:


Why not try reading config files containing network information? try this: adb shell cd /proc/uid_stat/XXXX(Proc id) cat tcp_rcv/tcp_snd



来源:https://stackoverflow.com/questions/18453099/how-to-obtain-amount-of-transferred-data-through-wi-fi-from-other-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!