2012-03-06 11 views
1

trafficstats API의 다음 메소드를 사용하여 특정 앱에 대해 모든 네트워크 인터페이스에 대해 보내고받은 바이트를 가져올 수 있음을 알고 있습니다. 하지만 모바일 용 통계는 어떻게 얻습니까? 그래서 나는 모바일과 와이파이 데이터를 분리 할 수있다.TrafficStats 특정 애플리케이션 전용 네트워크 인터페이스

getUidTxBytes (INT의 UID)
이 UID의 네트워크를 통해 전송 된 바이트 수를 가져옵니다.

getUidRxBytes (int uid)
이 UID에 대해 네트워크를 통해 수신 한 바이트 수를 가져옵니다.

API에서 누락 된 것 같습니다. 그리고 얻을 수있는 다른 방법 getUidMobileRxBytes (int uid)

답변

0

죄송 합니다만, UID 당이 아니라 전체 장치에 대한 인터페이스 별 통계 만 가져올 수 있습니다.

전체 인터페이스, UID 별 통계 및 인터페이스 별, 전체 장치 통계를 수집하고 전체 장치에 대한 인터페이스의 비율을 가정하여 UID 별 통계를 추정 할 수 있습니다 대략 그 개별 UID에 대한 비율입니다. 짧은 시간 동안 장치가 인터페이스를 주기적으로 전환하기 때문에 이것은 매우 정확할 수 있습니다.

1
package com.formation.traficstates; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.net.TrafficStats; 
import android.os.Bundle; 
import android.os.Handler; 
import android.widget.TextView; 

public class TraficstatesActivity extends Activity { 

    private Handler mHandler=new Handler();; 

    private long mStartRX; 





    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 


     mStartRX=TrafficStats.getTotalRxBytes(); 

     if (mStartRX == TrafficStats.UNSUPPORTED) { 

      AlertDialog.Builder alert = new AlertDialog.Builder(this); 

      alert.setTitle("Uh Oh!"); 

      alert.setMessage("Your device does not support traffic stat monitoring."); 

      alert.show(); 

     } else { 

      mHandler.postDelayed(mRunnable, 1000); 

     } 
    } 

    private final Runnable mRunnable = new Runnable() { 

     public void run() { 


     long rxBytes = TrafficStats.getTotalRxBytes()- mStartRX; 

     TextView RX = (TextView)findViewById(R.id.textViewRX); 

     RX.setText("\nbytes recreived :"+Long.toString(rxBytes)); 


     } 

     }; 

} 
관련 문제