Get wifi traffic stats android

左心房为你撑大大i 提交于 2019-12-01 05:31:21

I had the same problem a few years back and solved this by reading the system files directly.

private final String RX_FILE = "/sys/class/net/wlan0/statistics/rx_bytes";
private final String TX_FILE = "/sys/class/net/wlan0/statistics/tx_bytes";

    private long readFile(String fileName){
    File file = new File(fileName);
    BufferedReader br = null;
    long bytes = 0;
    try{
        br = new BufferedReader(new FileReader(file));
        String line = "";
        line = br.readLine();
        bytes = Long.parseLong(line);
    }  catch (Exception e){
        e.printStackTrace();
        return 0;

    } finally{
        if (br != null)
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }

    return bytes;
}

Hope it helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!