如何在Android环境中检测数据使用情况 [英] How to go about detecting data usage in the Android environment

查看:56
本文介绍了如何在Android环境中检测数据使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用Android环境检测所有形式的数据使用情况.是否可以保留关于哪些应用程序调用的选项卡,例如 RTP

I would like to be able to detect all forms of data usage using the Android environment. Is it possible to keep tabs on which applications call on say RTP vs WAP, etc. such that I can know at all times when data is being used by a native program or third-party app?

推荐答案

如果您要谈论的是通过应用程序监视网络统计信息的Android API,那么似乎已经在

If you are talking about an Android API to monitor network statistics by application then such an API seems to have been added in Android 2.2 (Froyo).

您需要的主要类是 TrafficStats .

The main class you'll need is TrafficStats.

您可以使用getUid{Rx|Tx}Bytes(int uid)作为给定的进程用户ID(可以从ActivityManager.getRunningAppProcesses()获取).

You can use getUid{Rx|Tx}Bytes(int uid) for the given process user ID (which you can get from ActivityManager.getRunningAppProcesses()).

API非常简单,仅提供了已接收/已发送的总字节数,因此您必须做更多的工作来跟踪每小时,每天和每月的统计信息.好吧,这一切都取决于您的需求.

The API is very simple and simply gives you the total bytes received/sent, so you'll have to do some more work to keep track of hourly, daily, and monthly stats. Well, that all depends on your needs.

我还没有尝试过使用它,所以我无法提供更多详细信息,也不知道支持的设备(API指出并非所有设备都支持此功能).

I haven't tried using it myself, so I cannot give you any more detail, nor do I know the supported devices (not all devices will support this as the API points out).

这篇关于如何在Android环境中检测数据使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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