开发者

Monitor data consumption in Android app?

I'm building an app that relies on a lot of online content. I'd like to monitor how much is being downloaded and attempt to minimize it as much as possible. These days, with more and more carriers impleme开发者_开发知识库nting data caps, users deserve an application that has gone through data consumption testing.


Well, not exactly advanced tools. But you can use iptables in the underlying Linux system to give you network info. I used this a little while ago to do a bit of tracking. You needed a rooted phone. I've only tried this out thus far on my G2, not sure how it would fare on an emulator or something of the sort. But assuming that you did have a rooted phone, which will have the iptables command available, can use iptables to segment some traffic off into a chain and then get the stats out of the chain:

iptables -N app
iptables -A OUTPUT -d a.b.c.d -j app

If you wanted to track data you were sending to IP a.b.c.d from your handset. Then you can dump the stats from iptables using "iptables -L -v -n" to get the packet count and byte count by rule.

Might not be the right solution for you given that you control the source of the program. But comes in really useful for monitoring when you don't have the ability to modify the code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜