I have searched a lot about this. Found the same code everywhere which solves the purpose partially. As API documentation says, it reset the counter once the device restarts. Sometimes the counter just resets even without the restart. Below is the code
float totalRxBytes = (float)TrafficStats.getTotalRxBytes()/(float)1048576; // Received
float totalTxBytes = (float)TrafficStats.getTotalTxBytes()/(float)1048576; // Sent
float mobRxBytes = (float)TrafficStats.getMobileRxBytes()/(float)1048576;
float mobTxBytes = (float)TrafficStats.getMobileTxBytes()/(float)1048576;
float wifiRxBytes = totalRxBytes - mobRxBytes;
float wifiTxBytes = totalTxBytes - mobTxBytes;
But I could not figure out any way to have this data from a specific date OR for a month? Please help. Any pointer will be appreciated. Thanks.