如何通过wifi和移动数据获取android上的数据使用情况? [英] How to get Data usage on android by both wifi and Mobile data?
问题描述
我需要获取Android手机上安装的每个应用程序的数据使用情况.
I need to get a data usage on each application installed on a android mobile.
例如:我在移动设备上安装了YouTube应用程序,我需要通过wifi和移动数据获取YouTube应用程序的数据使用情况.
Ex: I installed YouTube application on my mobile i need to get data usage of YouTube app by wifi and mobile data.
例外结果:
YouTube-无线网络-500MB.
YouTube - Wifi - 500MB.
YouTube-移动数据-100 KB
YouTube - Mobile Data - 100 KB
我尝试使用TrafficStats API
I try to use TrafficStats API
int mobileTx = TrafficStats.getMobileTxBytes();
int mobileRx = TrafficStats.getMobileRxBytes();
int wifiTx = TrafficStats.getTotalTxBytes() - mobileTx;
int wifiRx = TrafficStats.getTotalRxBytes() - mobileRx;
以上内容为我提供了整个移动数据的使用情况,但我需要针对每个应用程序进行获取.
the above give me the mobile entire data usage but i need to get per each application.
推荐答案
TrafficStats.getUidRxBytes(int uid)
和TrafficStats.getUidTxBytes(int uid)
在这种情况下可以为您提供帮助,因为这些静态方法提供有关某些UID自上次引导以来已接收和传输的字节的信息.为此,您需要找到需要详细信息的应用程序的UID.要找到应用程序的UID,您可以查看此线程-
TrafficStats.getUidRxBytes(int uid)
and TrafficStats.getUidTxBytes(int uid)
can help you out in this situation as these static methods provides info about bytes received and transmitted since last boot by some UID. for this you need to find UID of application for which you need detail. To find UID of application you can look into this thread - How to get uid value of an android application from a list displayed in a spinner?
这篇关于如何通过wifi和移动数据获取android上的数据使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!