如何在Android上按应用程序查找数据使用情况? [英] How can I find the data usage on a per-application basis on Android?

查看:106
本文介绍了如何在Android上按应用程序查找数据使用情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出每个应用程序在Android上的数据使用情况.类似于 .

I am trying to find out the data usage on Android on a per-application basis. Something like Android Data Usage Apps and Quota / Cap Monitor Widgets: never get charged extra for data or get capped again!.

我查看了堆栈溢出问题

I looked at Stack Overflow question How to go about detecting data usage in the Android environment.

但这并没有太大帮助.

ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo( mInfo );
List<RunningAppProcessInfo> listOfRunningProcess = activityManager.getRunningAppProcesses();
Log.d(TAG, "XXSize: " + listOfRunningProcess.size());

for (RunningAppProcessInfo runningAppProcessInfo : listOfRunningProcess) {

    if (runningAppProcessInfo.uid > 1026)
    {
        Log.d(TAG, "ANS " + runningAppProcessInfo.processName +
                   " Id :" + runningAppProcessInfo.pid +
                   " UID: " + runningAppProcessInfo.uid);
    }
}

我尝试了上面的代码,由Akos Cz建议作为.但是,所有 UID 都是数字,与上面提到的app_79不同.这样可以吗?

I tried the above code as suggested by Akos Cz. However all the UIDs are numbers, unlike app_79 as you have mentioned above. Is this all right?

推荐答案

以下链接应帮助您了解如何以编程方式确定每个应用程序的数据使用情况.

The following links should help you figure out how to programmatically determine the data usage per application.

使用Android的TrafficStats类创建网络监视器

Android内部流量统计

您将需要实现代码以使用 TraficStats API并跟踪每个UID(应用程序)发送/接收的字节数.

You will need to implement your code to use the TraficStats API and track the number of bytes sent/received per UID (application).

这篇关于如何在Android上按应用程序查找数据使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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