Measure data roaming traffic on Android?

Question:

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)

Answer:

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值