Android programmatically retrieves data for a specific application, for example: Using the data used in Facebook,

I would like to classify data usage:

OS ------60% (300MB used so far) Music ------ 10% (50MB used so far) Facebook -----5% (25MB used so far) 

Anyone can help me in solving this Android programming since I am starting Android development and would like to develop an application for monitoring mobile networks now. I would like to get data usage by specifying the name of the application.

Thanks. Hope to hear from all of you.

+4
source share
1 answer

Use http://developer.android.com/reference/android/net/TrafficStats.html#getUidRxBytes(int)

public static long getUidRxBytes (int uid)

Added to API level 8 Returned number of bytes received by this UID since device boot. Counts packets on all network interfaces and always increases monotonously from the moment the device boots. Statistics are measured at the network level, so they include the use of TCP and UDP.

Prior to JELLY_BEAN_MR2, this may return UNSUPPORTED on devices where statistics are not available.

See also myUid () uid

and

public static long getUidTxBytes (int uid)

Added to API level 8 Returns the number of bytes transferred to this UID since the device was booted. Counts packets on all network interfaces, and always monotonously increases from the moment the device boots. Statistics are measured at the network level, so they include the use of TCP and UDP.

Prior to JELLY_BEAN_MR2, this may return UNSUPPORTED on devices where statistics are not available.

See also myUid () uid

+4
source

All Articles