现在一天上网费用非常高昂。提供商使用地狱之类的费用。 我们不使用无限的互联网计划。这就是为什么我想开发一个可以计算(管理)网络包/数据使用情况的工具。Android如何计算网络使用数据包/数据
假设我已经激活了5GB的数据计划。所以我需要在网上冲浪,上传/下载东西之前检查一下。
我知道一些数据提供者提供这些设施。我想通过我的应用程序捕获我的android设备上的网络数据包。但是,我怎样才能将其写入我自己的代码中。 任何帮助将不胜感激。 谢谢提前
现在一天上网费用非常高昂。提供商使用地狱之类的费用。 我们不使用无限的互联网计划。这就是为什么我想开发一个可以计算(管理)网络包/数据使用情况的工具。Android如何计算网络使用数据包/数据
假设我已经激活了5GB的数据计划。所以我需要在网上冲浪,上传/下载东西之前检查一下。
我知道一些数据提供者提供这些设施。我想通过我的应用程序捕获我的android设备上的网络数据包。但是,我怎样才能将其写入我自己的代码中。 任何帮助将不胜感激。 谢谢提前
使用TrafficStats类在APILevel 8开始。 您获得每个无线接入技术和每个应用程序的整体使用情况。
见http://developer.android.com/reference/android/net/TrafficStats.html 这都是静态方法,例如呼叫TrafficStats.getMobileRxBytes()
非常感谢你.Could请您分享更多details.like链接一些教程... – Maidul
请检查。
TextView infoView = (TextView)findViewById(R.id.traffic_info);
String info = "";
info += "Mobile Interface:\n";
info += ("\tReceived: " + TrafficStats.getMobileRxBytes() + " bytes/" + TrafficStats.getMobileRxPackets() + " packets\n");
info += ("\tTransmitted: " + TrafficStats.getMobileTxBytes() + " bytes/" + TrafficStats.getMobileTxPackets() + " packets\n");
info += "All Network Interface:\n";
info += ("\tReceived: " + TrafficStats.getTotalRxBytes() + " bytes/" + TrafficStats.getTotalRxPackets() + " packets\n");
info += ("\tTransmitted: " + TrafficStats.getTotalTxBytes() + " bytes/" + TrafficStats.getTotalTxPackets() + " packets\n");
infoView.setText(info);
试试这个:http://developer.android.com/reference/android/net/TrafficStats.html – YuDroid