Is there any possible way for calculating mobile and wifi usage of each application in android using TrafficStats' : (getUidRxBytes,getUidTxBytes, getTotalRxbytes, getTotalTXbytes, getMobileRxBytes,getMobileTxBytes) methods ? I know there must be some way of doing that as 3G watchdog and some other application provide these details.
Can anybody help please ? Thanks
Open Settings | Data Usage. From that window, tap the menu button (three vertical dots in the upper right corner) and tap Show Wi-Fi (Figure D). Once it's enabled, you'll see a Wi-Fi tab listed (Figure E)–tap on that tab, and you can view your Wi-Fi data usage in the same way as you can cellular usage.
Go to the Account tab. At the top of the screen, you'll see your current data usage. Android: To see your daily breakdown select View overall or Daily data usage.
I've written a similar answer to this type of question here. For getting overall data usage per app it's fairly easy using the methods you named, TrafficStats.getUidTxBytes(int)
and TrafficStats.getUidRxBytes(int)
. However, breaking into mobile and Wifi is not something publicly available currently.
As I mention in my other answer, you'll have to dig into the internal frameworks APIs and try to copy some of the methods used there. You'll definitely need to use NetworkTemplate.buildTemplateWifiWildcard()
and NetworkTemplate.buildTemplateMobileWildcard()
in order to retrieve the correct NetworkStats
for each interface. Once you have the NetworkStats
object you'll be able to get your info. Just note: if you're using this in a public app, using internal APIs is very likely to break whenever Google decides to update them.
EDIT: as another tip, you should check out the source for how the Settings app is able to display traffic per app and separate it by Mobile/Wifi. In particular you can look here at their ChartDataLoader
, particularly the methods collectHistoryForUid()
and loadInBackground()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With