如何获取android

时间:2015-07-07 05:53:03

标签: android android-broadcast android-networking

我想在android中获取网络信息。这是来自谷歌镀铬窗口的图像。

enter image description here

您可以将其视为参考,但我需要找到一种方法在Android中实用地获取此信息

1 个答案:

答案 0 :(得分:0)

如果您想查看网络的流量使用情况,可以尝试以下方法:

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);