7

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!

Benny Skogberg
  • 10,431
  • 11
  • 53
  • 83
  • 1
    NetCounter measures data roaming traffic fine for me; I don't believe it differentiates between roaming or not. – Christopher Orr Aug 03 '10 at 11:18
  • That is strange... I use NetCounter on Samsung Galaxy i7500 (SDK 4 Android 1.6) and it is working on my home network before travel. When data roaming nothing happens - it just says 0 on every measurement. Coming home to my home network, it works again. Could it be an hardware issue due to Samsung? – Benny Skogberg Aug 03 '10 at 11:35
  • 1
    I know of this application, netmeter, maybe you could take a queue from its code! =) http://code.google.com/p/android-labs/wiki/NetMeter – Shouvik Aug 08 '10 at 17:33
  • Thanx Shouvik, I've downloaded it, and will try it when in Roam :) - BR – Benny Skogberg Aug 08 '10 at 19:56
  • 1
    I'd love to have this app when you've put something together. If you need a beta tester, let us know! – Paul Lammertsma Aug 09 '10 at 15:14
  • Thanx Paul... I found a need for it, and will solve it even if this question doesn't have a real answer yet. I'd love to have you as beta-tester when I have something up and running. BR - – Benny Skogberg Aug 09 '10 at 16:56

2 Answers2

9

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

LatinSuD
  • 1,779
  • 12
  • 19
  • Using Astro, both `/proc/net/dev` and all files within `/sys/class/net` are 0 byte, empty files. Can these files be accessed while the phone is running? Or is it just Astro that is not allowed to? (Motorola Droid, 2.1-u1) – Paul Lammertsma Aug 10 '10 at 15:55
  • Nevermind; it just appears to be Astro. I can open the files in a different app. I suppose you could just poll this file (or files) occasionally, and tally the results since the last poll. – Paul Lammertsma Aug 10 '10 at 15:59
  • This is really great news for me. Thanx for making this clear to me! BR - – Benny Skogberg Aug 10 '10 at 19:02
3

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

Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187