recived = TrafficStats.getUidRxBytes(uid);
send = TrafficStats.getUidTxBytes(uid);
TrafficStats.getMobileRxBytes();
TrafficStats.getMobileTxBytes();
TrafficStats.get
Unfortunately there are no public APIs to get that information as of API level 19; you've listed the TrafficStats
APIs that are publicly available. Android does it using internal APIs, so unless you're looking to go down that road (which is a really BAD idea and HIGHLY discouraged by Google), you're out of luck for now.
EDIT:
If you INSIST on using the internal APIs and risk your code breaking in various API versions, refer to the following links and be sure to read them thoroughly:
Recompiling Android SDK to use hidden and internal APIs
Recompiling Android SDK for Gingerbread and later
Once you have this implemented, this file will give you the most help in figuring it out:
packages/apps/Settings/src/com/android/settings/fuelgauge/BatteryStatsHelper.java
You'll have to either copy a lot of the code from the file or look for the processAppUsage()
function and pull whatever you need. In particular, look for these lines:
// Add cost of wifi traffic
final long wifiRx = u.getNetworkActivityCount(NETWORK_WIFI_RX_BYTES, mStatsType);
final long wifiTx = u.getNetworkActivityCount(NETWORK_WIFI_TX_BYTES, mStatsType);
One final note: Android JUST changed this code in KitKat (API 19) and is likely to change this again in the future. I cannot stress enough how this will break your app once they decide to change again.
I think you should use alternative way, get traffic by UID, for example — getUidRxPackets(int uid)
Also helpful (how get UID): (How to get all apps installed on android phone)
EDIT:
can you tell me how i can determine how much data use by wifi and mobile.??
There a nice answer — android statistic 3g traffic for each APP, how? look his logic.