We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
public long getTrafficInfo() {
RandomAccessFile rafTaffic = null; long traffic = 0; try { rafTaffic = new RandomAccessFile("/proc/net/xt_qtaguid/stats", "r"); Log.i(LOG_TAG, "get traffic information"); String line = ""; while ((line = rafTaffic.readLine()) != null) { Log.d(LOG_TAG, "line===" + line); String[] linesplits = line.split(" "); Log.d(LOG_TAG, "uid===" + uid); Log.d(LOG_TAG, linesplits[3]); if (linesplits[3].endsWith(uid)) { traffic = traffic + Long.parseLong(linesplits[5]) + Long.parseLong(linesplits[7]); } } } catch (FileNotFoundException e) { traffic = -1; } catch (NumberFormatException e) { Log.e(LOG_TAG, "NumberFormatException: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { Log.e(LOG_TAG, "IOException: " + e.getMessage()); e.printStackTrace(); } finally { try { if (rafTaffic != null) rafTaffic.close(); } catch (IOException e) { Log.i(LOG_TAG, "close randomAccessFile exception: " + e.getMessage()); } } Log.d(LOG_TAG, "Traffic===" + traffic); return traffic; }
The text was updated successfully, but these errors were encountered:
应该是4.4以后都不好使了,/proc/uid_stat/" + uid路径不存在,访问不到
改为从/proc/net/xt_qtaguid/stats取数据,个人认为这得数据比上边那个准确
Sorry, something went wrong.
首先十分感谢反馈,帮我们发现了Emmagee在高版本上流量获取的问题!
我们也看了源码,发现在 4.3.1 及之后的版本,确实如你所说,流量的统计都放到了/proc/net/xt_qtaguid/stats这个文件下,流量需要通过读取这个文件获取。
不过 Android API8 以后提供了getUidRxBytes以及getUidTxBytes方法,底层调用也是读取这个文件。所以通过这个方法更简单而且也同样准确,使用该方法获取的数据和你的算法应该是相同的。我们考虑下个版本使用该API来获取流量。
Fixed: #40 & #19 incorrect network traffic in some high level sdk
2d2a44f
No branches or pull requests
public long getTrafficInfo() {
The text was updated successfully, but these errors were encountered: