Get Wifi Traffic Stats Android
I am developping an app which allows to check wifi and mobile traffic stats on android. That's how I get the stats : long mobileStats = TrafficStats.getMobileRxBytes() + TrafficSta
Solution 1:
I had the same problem a few years back and solved this by reading the system files directly.
privatefinalStringRX_FILE="/sys/class/net/wlan0/statistics/rx_bytes";
privatefinalStringTX_FILE="/sys/class/net/wlan0/statistics/tx_bytes";
privatelongreadFile(String fileName){
Filefile=newFile(fileName);
BufferedReaderbr=null;
longbytes=0;
try{
br = newBufferedReader(newFileReader(file));
Stringline="";
line = br.readLine();
bytes = Long.parseLong(line);
} catch (Exception e){
e.printStackTrace();
return0;
} finally{
if (br != null)
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return bytes;
}
Hope it helps!
Post a Comment for "Get Wifi Traffic Stats Android"