Skip to content Skip to sidebar Skip to footer

How To Get Data Usage On Android By Both Wifi And Mobile Data?

I need to get a data usage on each application installed on a android mobile. Ex: I installed YouTube application on my mobile i need to get data usage of YouTube app by wifi and m

Solution 1:

TrafficStats.getUidRxBytes(int uid) and TrafficStats.getUidTxBytes(int uid) can help you out in this situation as these static methods provides info about bytes received and transmitted since last boot by some UID. for this you need to find UID of application for which you need detail. To find UID of application you can look into this thread - How to get uid value of an android application from a list displayed in a spinner?

Solution 2:

You can make use of getUidTxBytes API from TrafficStats class

long getUidTxBytes (int uid)
added in API level 8Return number of bytes transmitted by the given UID since device boot. Counts packets across all network interfaces, and always increases monotonically since device boot. Statistics are measured at the network layer, so they include both TCP and UDP usage.
Before JELLY_BEAN_MR2, this may return UNSUPPORTED on devices where statistics aren't available.
Starting in N this will only report traffic statistics for the calling UID. It will return UNSUPPORTED for all other UIDs for privacy reasons. To access historical network statistics belonging to other UIDs, use NetworkStatsManager.

Although this also tells that you will have to make use of NetworkStatsManager to get network stats history of other than the calling apps.

Here uid is identifier of this process's uid

Post a Comment for "How To Get Data Usage On Android By Both Wifi And Mobile Data?"