android download upload internet bytes

September 10, 2012   ·   0 Comments

Screen Shot 2012-09-10 at 9.41.59 AM

android download upload internet bytes

source code: com.powenko.tutorial_network_speed

package com.powenko.tutorial_network_speed;

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

public class MainActivity extends Activity {
	private Handler mHandler = new Handler();
	private long mStartRX = 0;
	private long mStartTX = 0;
	
	

	    @Override
	    public boolean onCreateOptionsMenu(Menu menu) {
	        getMenuInflater().inflate(R.menu.activity_main, menu);
	        return true;
	    }
	    
	    public void onCreate(Bundle savedInstanceState) {
	    	super.onCreate(savedInstanceState);
	        setContentView(R.layout.activity_main);
	    	mStartRX = TrafficStats.getTotalRxBytes();
	    	mStartTX = TrafficStats.getTotalTxBytes();
	    	if (mStartRX == TrafficStats.UNSUPPORTED || mStartTX == 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() {
	    	TextView RX = (TextView)findViewById(R.id.RX);
	    	TextView TX = (TextView)findViewById(R.id.TX);
	    	long rxBytes = TrafficStats.getTotalRxBytes()- mStartRX;
	    	RX.setText(Long.toString(rxBytes));
	    	long txBytes = TrafficStats.getTotalTxBytes()- mStartTX;
	    	TX.setText(Long.toString(txBytes));
	    	mHandler.postDelayed(mRunnable, 1000);
	    	}
	    	};
}


shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon