Android以编程方式获取特定应用的数据使用情况,例如:在“Facebook”上使用的数据使用情况。 [英] Android programmatically get data usage for specific app, for example: Data Usage used on "Facebook"

查看:142
本文介绍了Android以编程方式获取特定应用的数据使用情况,例如:在“Facebook”上使用的数据使用情况。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按以下方式对数据使用情况进行分类:

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)

任何人都可以帮助我解决这个Android编程,因为我是Android开发的初学者,并且希望目前开发一个移动网络监控应用程序。
我想通过指定应用名称来获取数据。

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.

推荐答案

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


public static long getUidRxBytes(int uid)

public static long getUidRxBytes (int uid)

在API级别8中添加返回的数量自设备启动后由给定UID
接收的字节数。在所有网络接口上计算数据包,并且
总是在设备启动后单调增加。统计数据是在网络层测量的
,因此它们包括TCP和UDP使用。

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.

在JELLY_BEAN_MR2之前,这可能会在
的设备上返回UNSUPPORTED统计数据不可用。

Before JELLY_BEAN_MR2, this may return UNSUPPORTED on devices where statistics aren't available.

另见myUid()uid

See Also myUid() uid


public static long getUidTxBytes(int uid)

public static long getUidTxBytes (int uid)

在API级别添加8返回自设备启动以来给定的
UID传输的字节数。在所有网络接口上计算数据包,
并且自设备启动以来总是单调增加。统计数据是在网络层测量的
,因此它们包括TCP和UDP使用。

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.

在JELLY_BEAN_MR2之前,这可能会在
的设备上返回UNSUPPORTED统计数据不可用。

Before JELLY_BEAN_MR2, this may return UNSUPPORTED on devices where statistics aren't available.

另见myUid()uid

See Also myUid() uid

这篇关于Android以编程方式获取特定应用的数据使用情况,例如:在“Facebook”上使用的数据使用情况。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆