Measure data roaming traffic on Android?

前端 未结 2 729
庸人自扰
庸人自扰 2020-12-30 13:48

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

相关标签:
2条回答
  • 2020-12-30 13:55

    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

    0 讨论(0)
  • 2020-12-30 14:08

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

    • NetCounter
    • NetMeter

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

    0 讨论(0)
提交回复
热议问题