获得通过ADB网络/数据使用 [英] getting network/data usage via adb

查看:1188
本文介绍了获得通过ADB网络/数据使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待找出一个应用程序有多少数据的发送和接收通过亚行/亚行外壳

I am looking to figure out how much data an application is sending and receiving on an android handset running 2.3 through adb/adb shell

我已经发现的最接近线程是这样

The closest thread I have found was this

<一个href=\"http://stackoverflow.com/questions/12904809/tracking-an-applications-network-statistics-netstats-using-adb\">Tracking应用程序的网络统计(netstats)使用ADB

但它不为我工作。

我非常希望看到网络统计对于一个给定应用程序,也知道如何擦除/如果需要重置这些统计数据。

Ideally I would like to see the network stats for a given application and also know how to wipe/reset these stats if needed.

任何想法?

推荐答案

您可以使用的 trafficStats 类来计算的针对不同的应用使用互联网安装在设备中如果使用的亚行/亚行外壳是不是一个必要条件。

You can use trafficStats class to calculate internet usage for different applications installed in the device if using adb/adb shell isn't a necessary requirement

       final PackageManager pm = getPackageManager();
        // get a list of installed apps.
        List<ApplicationInfo> packages = pm
                .getInstalledApplications(PackageManager.GET_META_DATA);

        // loop through the list of installed packages and see if the selected
        // app is in the list
        for (ApplicationInfo packageInfo : packages) {

        // get the UID for the selected app
        UID = packageInfo.uid;
          //internet usage for particular app(sent and received) 
        long recived = TrafficStats.getUidRxBytes(UID);
        long send = TrafficStats.getUidTxBytes(UID);


        }

互联网使用你的应用程序只:

receivedMbs = (double) TrafficStats.getUidRxBytes(android.os.Process
                .myUid()) / (1024 * 1024);
sentMbs = (double) TrafficStats.getUidTxBytes(android.os.Process
                .myUid()) / (1024 * 1024);

相关链接:

<一个href=\"http://stackoverflow.com/questions/7638292/trafficstats-api-android-and-calculation-of-daily-data-usage\">TrafficStats API的Andr​​oid和日常数据使用计算

<一个href=\"http://www.techrepublic.com/blog/app-builder/create-a-network-monitor-using-androids-trafficstats-class/774\"相对=nofollow>流量统计的例子

希望它帮助。

这篇关于获得通过ADB网络/数据使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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