如何获取网络流量数据

时间:2016-02-17 13:00:54

标签: java android linux tethering

我正在做一个存储流量数据的应用程序,但我无法获得网络共享流量。

    // UIDs for Tethering ?
    appNames.put(5, "Tethering WiFi");
    appNames.put(7, "Tethering USB");
    appNames.put(10, "Tethering BT");
    appNames.put(11, "Tethering Unknown");


    appNames.put(-5, "!Tethering WiFi");
    appNames.put(-7, "!Tethering USB");
    appNames.put(-10, "!Tethering BT");
    appNames.put(-11, "!Tethering Unknown");

    for(ApplicationInfo app : cnt.getPackageManager().getInstalledApplications(0))
    {
        appNames.put(app.uid, app.packageName);
    }

    for(Integer uid: appNames.keySet())
    {
        apps.put(uid, new TrafficRecord(uid, appNames.get(uid)));
    }



TrafficRecord(int uid, String tag)
{
    tx = TrafficStats.getUidTxBytes(uid);
    rx = TrafficStats.getUidRxBytes(uid);
    this.tag = tag;
}

但是Tethering流量数据始终为空。 我怎么能这样做?

0 个答案:

没有答案