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

2023-09-06 17:13:32 作者:安徒生最愛騙小孩

我开发一个Android应用程序,需要下载大量的数据。

要提高可用性,我想衡量我的应用程序产生的数据流量,给用户一个提示,如果应用程序下载的数据的具体金额。

我目前的想法:和所有下载字节一起,在规定限额反应。 然而,正如我下载的东西,在许多不同的情况,并在code很多不同的位置,有没有其他的方法可行,测量每个应用程序中的数据使用?

AFAIK SYS / NET / NETINTERFACE /统计/ rx_bytes 报告整个系统的总金额,所以这不是一个解决方案。

解决方案   

不过,正如我下载的东西,在许多不同的情况,并在code很多不同的位置,有没有其他的方法可行,测量每个应用程序中的数据使用?

TrafficStats可能能够通过的UID来报告的事情。我说可能,因为它似乎依赖于设备。我怀疑的Andr​​oid 3.0+将始终如一地通过UID报告,但我的2.2和2.3的经验有好有坏。

这里是展示记录这些信息的示例应用程序。

乐享动计步器 乐享动app下载 v2.3.7 安卓版 比克尔下载

I'm developing an Android app which needs to download a lot of data.

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 possiblity to measure the data usage per app?

AFAIKsys/net/NETINTERFACE/statistics/rx_bytes reports the total amount of the whole system, so this is not a solution.

解决方案

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. 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.

Here is a sample application demonstrating recording this information.