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));
}
};
}