I know I can use the following methods of trafficstats api to get bytes sent and received for ALL network interfaces for any given app. But how do I get stats for only mobile? So that I can seperate mobile and wifi data.
getUidTxBytes(int uid)
Get the number of bytes sent through the
network for this UID.getUidRxBytes(int uid)
Get the number of bytes received through the
network for this UID.
Seems like something like this is missing from API. And other way to get it
getUidMobileRxBytes(int uid)
Sorry, but you can only get per-interface stats for the entire device, not per UID.
You can estimate per-interface, per-UID stats by collecting both the all-interface, per-UID stats and the per-interface, whole-device stats, then assuming that the ratio of the interfaces for the whole device is approximately the ratio that would be for that individual UID. For short time spans, this is likely to be fairly accurate, as the device will only switch interfaces periodically.