测量 Android 上的数据漫游流量?

发布于 2024-09-13 03:11:03 字数 811 浏览 6 评论 0原文

刚从冰岛度过一个愉快的假期回来,正在等待我的电话公司的数据漫游账单。我希望尽可能限制我的流量,但我想提前知道。我使用了非常好的应用程序NetCounter,但它根本没有测量漫游数据流量。

所以我想构建自己的应用程序,仅测量漫游数据流量。我有一些布尔值开始( NetworkInfo.IsRoaming()< /a> & TelephonyManager.isNetworkRoaming() ) ,但我不确定如何测量 true 的流量。

那么问题是:如何测量漫游时的数据流量? (我使用的是 API 级别 8 TrafficStats 功能m 之后,但适用于 API 级别 3)。使用的智能手机是 Samsung Galaxy i7500 (Android 1.6)

感谢您的宝贵时间!

Just back from a very nice vacation in Iceland, and await the data roaming bill from my phone company. I hope for the best having limited my traffic as much as possible, but I want to know in advance. I used the very nice app NetCounter but it didn't measure roaming data traffic at all.

So I want to build my own app measuring just roaming data traffic. I have a few booleans to start with ( NetworkInfo.IsRoaming() & TelephonyManager.isNetworkRoaming() ), but I'm not sure how to measure the traffic if true.

So the question is: How do I measure data traffic while roaming? (Something like API level 8 TrafficStats functionality is what I'm after, but for API level 3). The used SmartPhone is Samsung Galaxy i7500 (Android 1.6)

Thanx for your time!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白色秋天 2024-09-20 03:11:03

方法一、解析“/proc/net/dev”。

在我的手机中,它看起来像:

Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:     712       8    0    0    0     0          0         0      712       8    0    0    0     0       0          0
dummy0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet1:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet2:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
 wlan0:  146112     423   32    0    0     0          0         0    42460     409    0    0    0     0       0          0

在我的手机中,“rmnet0”行是保存移动线路互联网统计信息的行。我希望它的格式不会因内核版本而异。

方法二:解析“/sys/class/net”。

我想这是推荐的方法。
如图所示: http: //www.jaqpot.net/svn/android/netcounter/trunk/src/net/jaqpot/netcounter/service/SysClassNet.java

Method 1. Parse "/proc/net/dev".

In my phone it looks like:

Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:     712       8    0    0    0     0          0         0      712       8    0    0    0     0       0          0
dummy0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet1:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet2:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
 wlan0:  146112     423   32    0    0     0          0         0    42460     409    0    0    0     0       0          0

In my phone the "rmnet0" row is the one that holds the stats for mobile line internet. I hope its format does not vary among kernel versions.

Method 2: Parse "/sys/class/net".

I guess this is the recommended method.
As shown here: http://www.jaqpot.net/svn/android/netcounter/trunk/src/net/jaqpot/netcounter/service/SysClassNet.java

淡淡绿茶香 2024-09-20 03:11:03

评论中提到了几个开源选项:

我目前安装的是3G Watchdog。 有一些作者的评论AndroLib 表明他不愿意发布源代码,但在社区的一些帮助下,我相信我们可以合作制作出最好的数据使用应用程序。

我认为最好的解决方案是从 NetMeter 获取代码并在后台运行一个服务。 3G Watchdog 执行此操作(该服务称为 net.NetMonitorService)。

There are a couple of open-source options that have been mentioned in the comments:

The one I presently have installed is 3G Watchdog. There are a few comments by the author on AndroLib suggesting that he is reluctant to release the source code, but with some aid from the community, I'm sure we could all collaborate to make the best data usage app out there.

I think the best solution would be to take the code from NetMeter and have a service run in the background. 3G Watchdog does this (the service is called net.NetMonitorService).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文