在Android Q中,如何跟踪应用程序&x27;s网络统计(接收和发送)
在Android Q中,如何跟踪应用程序的网络统计信息(rx和tx)。在安卓10中没有使用下面的代码获得rx和tx。这是一个没有任何问题的pie在Android Q中,如何跟踪应用程序&x27;s网络统计(接收和发送),android,networking,statistics,privacy,android-10.0,Android,Networking,Statistics,Privacy,Android 10.0,在Android Q中,如何跟踪应用程序的网络统计信息(rx和tx)。在安卓10中没有使用下面的代码获得rx和tx。这是一个没有任何问题的pie while (!Thread.currentThread().isInterrupted()) { // Parse the network traffic statistics pertaining to this connection DataInputStream in = null;
while (!Thread.currentThread().isInterrupted()) {
// Parse the network traffic statistics pertaining to this connection
DataInputStream in = null;
try {
in = new DataInputStream(new FileInputStream("/proc/net/dev"));
final String prefix = "tun0" + ':';
while (true) {
String line = in.readLine().trim();
if (line.startsWith(prefix)) {
String[] numbers = line.substring(prefix.length()).split(" +");
boolean foundNonZero = false;
for (int i = 1; i < 17 && foundNonZero == false; ++i) {
if (!numbers[i].equals("0")) {
foundNonZero = true;
}
}
if (foundNonZero) {
rxBytes = numbers[NET_INTERFACE_BYTES_IN_COL];
txBytes = numbers[NET_INTERFACE_BYTES_OUT_COL];
}
break;
}
}
} catch (Exception e) {
// ignore
} finally {
try {
in.close();
} catch (Exception e) {
// ignore
}
}
while(!Thread.currentThread().isInterrupted()){
//分析与此连接相关的网络流量统计信息
DataInputStream in=null;
试一试{
in=newdatainputstream(newfileinputstream(“/proc/net/dev”);
最后一个字符串前缀=“tun0”+”:”;
while(true){
String line=in.readLine().trim();
if(行起始带(前缀)){
String[]number=line.substring(prefix.length()).split(“+”);
布尔值foundNonZero=false;
对于(int i=1;i<17&&foundNonZero==false;++i){
如果(!number[i].等于(“0”)){
foundNonZero=true;
}
}
如果(非零){
rxBytes=数字[网络接口字节数];
txBytes=数字[网络接口字节输出列];
}
打破
}
}
}捕获(例外e){
//忽略
}最后{
试一试{
in.close();
}捕获(例外e){
//忽略
}
}
TrafficStats
已经存在多年了。但是在没有接入网络的情况下,它每秒钟都在变化。我使用vpn还有其他解决方案吗?