2014-02-27 2 views
0

이 프로그램을 만들고 TrafficStats.getUidRxBytes() 메소드를 사용하면 항상 0이됩니다. 내 앱과 데이터 사용 기록이 있는지 확인하지만 코드에 수신 된 데이터 사용량이 표시되지 않고 데이터 양이 전송됩니다. 또한 "System.out.println ("Recieved Bytes : "+ re +"\ n "+"Send Bytes : "+ sd +"\ n ");"을 출력하면 logcat은 단지 인쇄 만한다는 것을 보여줍니다 처음에는 항상 pid.TrafficStats.getUidRxBytes() 모든 프로세스에 대해 0을 부여합니다.

이 문제에 대한 해결책 ???

가 여기 내 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; 
} 
+0

에뮬레이터 또는 실제 장치에서 이것을 실행하고 있습니까? – user1406716

답변

0

이것은 어떤 사람들은 안드로이드 4.4에 고정있어 그 주장 알려진 버그.

Here's이 문제가보고 된 곳의 here's입니다.

기본적으로 "/ proc/uid_stat /"에있는 파일을 구문 분석하면됩니다. 각 폴더에는 applicationInfo의 UID 이름 (각 앱의 이름)이 있습니다. 첫 번째 행은받은 바이트 수이고 두 번째 행은 전송 된 바이트 수입니다.

관련 문제