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

亡梦爱人 提交于 2019-12-18 17:24:09

问题


I would like to categorize the data usage by:

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 as I am a beginner of Android development and would like to develop a mobile network monitor app currently. I would like to get the data usage by specifying the app name.

Thank you. Hope to hear from you all.


回答1:


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



来源:https://stackoverflow.com/questions/31922203/android-programmatically-get-data-usage-for-specific-app-for-example-data-usag

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