问题
I want to read the network statistics on my Nexus 7 from the file system. On all devices tested before, the network statistics (e.g., tx_packets) were always located in
/sys/devices/virtual/net/wlan
However, although on the Nexus 7 there are four matching sub directories
/sys/devices/virtual/net/dummy
/sys/devices/virtual/net/ip6tnl0
/sys/devices/virtual/net/lo
/sys/devices/virtual/net/sit0
none of them seems to provide the right statistics, as all their statistic files do not change during Web access via WiFi.
Any sugestions where I might look as well?
回答1:
try the directory: /sys/class/net/iface/statistics/tx_packets
Example for wlan0
long txPackets= 0; //tx Packets
String cmd="cat /sys/class/net/wlan0/statistics/tx_packets\n";
Process p=null;
BufferedReader in2=null;
try {
p = Runtime.getRuntime().exec(cmd);
in2 = new BufferedReader(new InputStreamReader(p.getInputStream()));
txPackets= Long.parseLong(in2.readLine());
}catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
来源:https://stackoverflow.com/questions/12854866/network-statistics-on-nexus-7