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

前端 未结 1 1499
萌比男神i
萌比男神i 2021-01-03 05:11

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)


        
相关标签:
1条回答
  • 2021-01-03 05: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

    0 讨论(0)
提交回复
热议问题