Measure data roaming traffic on Android?
Asked Answered
F

2

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!

Freezedry answered 3/8, 2010 at 7:44 Comment(6)
NetCounter measures data roaming traffic fine for me; I don't believe it differentiates between roaming or not.Suburbicarian
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?Freezedry
I know of this application, netmeter, maybe you could take a queue from its code! =) code.google.com/p/android-labs/wiki/NetMeterPeriodicity
Thanx Shouvik, I've downloaded it, and will try it when in Roam :) - BRFreezedry
I'd love to have this app when you've put something together. If you need a beta tester, let us know!Fredkin
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 -Freezedry
A
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

Affiliation answered 10/8, 2010 at 12:12 Comment(3)
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)Fredkin
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.Fredkin
This is really great news for me. Thanx for making this clear to me! BR -Freezedry
F
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).

Fredkin answered 9/8, 2010 at 19:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.