gpt4 book ai didi

android - TrafficStats.getUidRxBytes() 为所有进程提供 0

转载 作者:行者123 更新时间:2023-11-30 03:04:16 32 4
gpt4 key购买 nike

我制作了这个程序,我的 TrafficStats.getUidRxBytes() 方法一直给我 0。我检查了我的应用程序并有数据使用记录,但我的代码没有显示接收和发送数据量的数据使用量。另外,当我打印这个“System.out.println("Recieved Bytes: "+re +"\n"+ "Send Bytes: "+sd+"\n"); 时,logcat 显示它只打印了第一个一直都是 pid。

这个问题有什么解决办法吗???

这是我的 MainActivity 类:-

public class MainActivity extends Activity {

static ArrayList<Integer> arr1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


TextView textView1 = (TextView) findViewById(R.id.textView1);

//this.setContentView(textView1);


ActivityManager actvityManager = (ActivityManager)
this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
ArrayList<Integer> a1 = new ArrayList<Integer>();
for(int i = 0; i < procInfos.size(); i++)
{
textView1.setText(textView1.getText().toString()+procInfos.get(i).processName+" "+procInfos.get(i).pid+
" " + String.valueOf(procInfos.get(i).processName.length())+"\n");
//if(procInfos.get(i).processName.equals("com.android.camera")) {
//Toast.makeText(getApplicationContext(), "Camera App is running", Toast.LENGTH_LONG).show();
//}
a1.add(procInfos.get(i).pid);


}

TextView textView2 = (TextView) findViewById(R.id.textView2);
TextView textView3 = (TextView) findViewById(R.id.textView3);
for(Integer a2 : a1){
long re = TrafficStats.getUidRxBytes(a2);
long sd = TrafficStats.getUidTxBytes(a2);

//arr1.add(a2);

System.out.println("Recieved Bytes: "+re/1000 + "Send Bytes: "+sd/1000);


textView2.append(""+Long.toString(re));
textView3.append("ABAABABBA");
textView3.invalidate();

}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

最佳答案

这是一个已知错误,有人声称已在 Android 4.4 上修复。

Here's一种处理它的方法,以及here's报告此问题的地方。

基本上,您需要做的是解析位于“/proc/uid_stat/”的文件。每个文件夹都有(每个应用程序的)applicationInfo 的 UID 的名称。第一行是接收到的字节数,第二行是发送的字节数。

关于android - TrafficStats.getUidRxBytes() 为所有进程提供 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22067291/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com