寻找其他Android应用程序有多少网络流量生成 [英] Find how much network traffic other Android apps generate

查看:108
本文介绍了寻找其他Android应用程序有多少网络流量生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让这应该测量流量使用各种应用程序的后台服务,以便能够显示到哪些应用程序消耗大部分数据流量的用户。

I am trying to make a background service which should measure traffic usage of various applications so as to be able to show to the user which apps consume most data traffic.

我发现,零配件的应用程序正是这么做的,但1.6的Dell Streak设备上安装它后,我总是得到无电池使用的数据用的网络使用。在备件的所有工作,这种功能? 另外,我无法找到一个工作源$ C ​​$ C备件。

I found that Spare Parts app does exactly that, but after installing it on a 1.6 Dell Streak device I always get "No battery usage data available" for "Network usage". Does this function at all work in Spare Parts? Also, I couldn't find a working source code for Spare Parts.

http://android.git.kernel.org/?p=platform/development.git;a=tree;f=apps/SpareParts;hb=HEAD

看起来已经过时或不完整。 (?)

looks to be outdated or incomplete. (?)

不过,备件,似乎测量例如每个应用程序的CPU使用率。它是如何做到这一点在一个无根的手机吗?

But Spare Parts seems to measure e.g. CPU usage per app. How does it do that on an unrooted phone?

我一般每次是如何应用的流量可以衡量的想法是要定期检查

My general idea of how traffic per app could be measured is to regularly check the

SYS /班/网/+ sWiFiInterface +/统计/ rx_bytes

SYS /班/网/+ sWiFiInterface +/统计/ tx_bytes

SYS /班/网/+ sMobileInterface +/统计/ rx_bytes

SYS /班/网/+ sMobileInterface +/统计/ tx_bytes

的文件和以查看哪个应用当前具有焦点并因此最有可能造成所生成的网络流量。

files and to see which app currently has focus and thus most likely to cause the generated network traffic.

不幸的是我无法找到如何让应用程序目前有焦点的。

Unfortunately I can't find how to get the app currently having focus.

我发现这一点:

<一个href="http://stackoverflow.com/questions/1558750/android-how-to-get-information-on-which-activity-is-currently-showing-in-forego">Android,如何获得该活动目前呈现(在foregorund)?

但似乎它是关于测试,不只是在无根的Andr​​oid设备上运行。3D第三方服务

but seems it's about testing, not just a 3d party service running on non-rooted Android device.

我们可以得到什么样的活动都与 ActivityManager.getCurrentTasks()运行,但任何人都可以成为一个重点。这似乎出于安全考虑,如Android的建筑师明确不希望3D方应用程序知道应用程序具有焦点,

We can get what activities are running with ActivityManager.getCurrentTasks(), but any of them can be the one with focus. It seems like the Android architects explicitly don't want 3d party apps to know what app has focus, because of security concerns

(见 http://android.bigresource.com/Track/android-zb2mhvZX4/ )。

有没有解决的办法吗?

另外,如果我想不仅能探测到它的活动吃起来的流量还需要什么服务,我可以得到所有与当前运行的服务 ActivityManager.getCurrentSerives() 甚至看到每一个,如果它在前台模式(不像丢在外面,如果机器人需要资源)。但是,这一次并没有给我带来任何远。

Also, if I want to not only detect which activities eat up traffic but also what services, I can get all currently running services with ActivityManager.getCurrentSerives() and even see for each one if it's in foreground mode (unlike to be thrown out if Android needs resources). But this again doesn't bring me any far.

任何想法?

推荐答案

您可以检测当前前台应用程序与 ActivityManager.getRunningAppProcesses 通话。它会返回 RunningAppProcessInfo 记录的列表。要确定哪些应用程序在前台办理入住手续 RunningAppProcessInfo.importance 字段平等 RunningAppProcessInfo.IMPORTANCE_FOREGROUND

You can detect currently foreground application with ActivityManager.getRunningAppProcesses call. It will return a list of RunningAppProcessInfo records. To determine which application is on foreground check RunningAppProcessInfo.importance field for equality to RunningAppProcessInfo.IMPORTANCE_FOREGROUND.

不过是洁具的来电 ActivityManager.getRunningAppProcesses()方法必须不在UI线程执行。只需调用它(通过AsyncTask的为例)的后台线程,它会返回正确的结果。检查<一href="http://stackoverflow.com/questions/2314969/how-to-determine-if-one-of-my-activities-is-in-the-foreground/5221315#5221315">my帖子了解更多详情。

But be ware that call to ActivityManager.getRunningAppProcesses() method must be performed NOT in the UI thread. Just call it in the background thread (for example via AsyncTask) and it will return correct results. Check my post for additional details.

这篇关于寻找其他Android应用程序有多少网络流量生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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