I am trying to calculate mobile data usage so I am using a broadcast that inform me about 3G connection then I run a Service to count data.
The problem is the calculating value is always less than the value calculated by the Android data usage default app.
Here is the code :
long now = TrafficStats.getMobileRxBytes();
long before  = now;
do {
    now = TrafficStats.getMobileRxBytes() ;
    Diffnow = now - before;
    SystemClock.sleep(500);
}while ((cm.getActiveNetworkInfo() != null) && (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE));
Log.i(TAG,"delta  = "+(float)Diffnow/(1024*1024));