如何衡量我的应用程序的数据使用 [英] How to measure data usage of my app

查看:139
本文介绍了如何衡量我的应用程序的数据使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

解决方案
  

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

<一个href="http://developer.android.com/reference/android/net/TrafficStats.html"><$c$c>TrafficStats可能能够通过的UID来报告的事情。我说可能,因为它似乎依赖于设备。我怀疑的Andr​​oid 3.0+将始终如一地通过UID报告,但我的2.2和2.3的经验有好有坏。

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

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.

这篇关于如何衡量我的应用程序的数据使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆