Android programmatically get data usage for specific app, for example: Data Usage used on “Facebook”

混江龙づ霸主 提交于 2019-11-30 15:40:58

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

public static long getUidRxBytes (int uid)

Added in API level 8 Return number of bytes received 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.

See Also myUid() uid

and

public static long getUidTxBytes (int uid)

Added in API level 8 Return 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.

See Also myUid() uid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!