简体   繁体   English

如何衡量我的应用程序的数据使用情况

[英]How to measure data usage of my app

I'm developing an Android app which needs to download a lot of data.我正在开发一个需要下载大量数据的 Android 应用程序。

To improve the usability, I'd like to measure the data traffic my app produces and give the users a hint if the app downloaded a specific amount of data.为了提高可用性,我想测量我的应用程序产生的数据流量,并在应用程序下载特定数量的数据时向用户提供提示。

My current idea: Sum all downloaded bytes together and react on a specified limit.我目前的想法:将所有下载的字节加在一起并在指定的限制上做出反应。 However, as I downloaded things in many different situations and in many different positions in the code, is there any other possibility to measure the data usage per app?但是,当我在许多不同情况下和代码中的许多不同位置下载东西时,是否还有其他可能来衡量每个应用程序的数据使用情况?

AFAIK, sys/net/NETINTERFACE/statistics/rx_bytes reports the total amount of the whole system, so this is not a solution. AFAIK, sys/net/NETINTERFACE/statistics/rx_bytes报告整个系统的总量,所以这不是一个解决方案。

However, as I downloaded things in many different situations and in many different positions in the code, is there any other possiblity to measure the data usage per app?但是,当我在许多不同情况下和代码中的许多不同位置下载东西时,是否还有其他可能来衡量每个应用程序的数据使用情况?

TrafficStats may be able to report things by UID. TrafficStats可能能够通过 UID 报告事物。 I say "may" because it seems tied to devices.我说“可能”是因为它似乎与设备有关。 I suspect that Android 3.0+ will consistently report by UID, but my 2.2 and 2.3 experience has been mixed.我怀疑 Android 3.0+ 会一直通过 UID 报告,但我的 2.2 和 2.3 体验是混合的。

Here is a sample application demonstrating recording this information. 这是一个示例应用程序,演示了如何记录此信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM