Android is a Linux based Operating System with java programming interface primarily designed for smartphones and tablets. Android was initially developed by Android, Inc., and was purchased by Google in 2005. The applications for android can be downloaded from Google Play, Android’s primary app store.

Android Versions

The different android versions with API level and code names.


Code Name

API Level


Jelly Bean



Jelly Bean



Ice Cream Sandwich



Honey Comb



Honey Comb


2.3.3 – 2.3.7

Ginger Bread


2.3 – 2.3.2

Ginger Bread





2.0 – 2.1







How To Enable Your System for Android Application Development ?

The tools required for Android application development can be obtained and installed free. The installation process:

  • Install latest version of Java.
  • If you dont have Eclipse installed in your system, install Eclipse IDE for Java developers.
  • Download Android SDK for your platform(Windows/Linux/Mac OS X).
  • Extract the the downloaded file to somewhere in your hard disk.
  • Run Eclipse and choose Help->Install New Software.
  • Click Add in the new pop up window.
  • Enter Android Development Tools in the Name field and in the Location field.
  • Click Next and Finish to install the plugin. You’ll need to restart Eclipse once everything is installed.
  • When Eclipse restarts, choose Window->Preferences and you should see Android listed in the categories.
  • You now need to tell Eclipse where you’ve installed the Android SDK. Click Android and then Browse to select the location where you extracted the SDK files.
  • Click OK to have Eclipse save the location of your SDK.


How to start Android application development ?

To start writing Android applications, you need to download SDK platforms for the android devices.

  • Choose Window->Android SDK Manager in Eclipse.
  • Click Available Packages in the left column and check the repository to show a list of the available Android platforms.
  • You can choose which platforms to download from the list. When you’re done, click Install Selected and follow the installation instructions.


Creating new Android Application

New project wizard in Eclipse will let you create a new android project. Let’s create a new Android application ‘Data Usage Tracker’. This application will display the internet connection state, network signal level and the data usage information in bytes. To start creating a new application :

  • Choose File->New->Project.


  • Select Android Application Project.
  • In the New Android Application dialog, enter the following as shown in picture below.
  • Click Next and choose an icon from Configure Launcher Icon dialog box.
  • Click Next. From the Create Activity dialog box, select Blank Activity and click Next.
  • In the New Blank Activity dialog box, enter the following as shown in picture below.
  • When you are done click Finish. A new Android Project created in your workspace.


The Coding Part of Data Usage Tracker

Now open AndroidManifest.xml in Eclipse by double clicking it in package explorer, and add the following lines in it.

<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>

<uses-permission android:name=”android.permission.CHANGE_NETWORK_STATE”/>

<uses-permission android:name=”android.permission.READ_PHONE_STATE”/>

<uses-permission android:name=”android.permission.ACCESS_COARSE_UPDATES”/>

These are the permissions to access above features from Android System by ‘Data Usage Tracker’.

Next, you are going to create the user interface or layout for ‘Data usage Tracker’. The user interfaces are created as XML files. The layout file are generally stored in res/layout folder. The Eclipse allows us to create the layout in graphical mode by dragging and dropping controls. It’s easier to write the interface in XML file.

  • Open res/layout/activity_tracker.xml in Eclipse.
  • Now change the content of activity_tracker.xml to:





    android:layout_height=“match_parent” >









        android:text=“ConnectionState:” />

















        android:text=“SignalLevel:” />








        android:layout_marginTop=“35dp” />








        android:textAppearance=“?android:attr/textAppearanceSmall” />










        android:layout_alignLeft=“@+id/connectionStateInfo” />


Now it’s the time to work with interface using the java code. The java files resides in src/<package name> folder. Now open the src/ When you open this file, you can see onCreate() method. This is the method that gets called first whenever you run your application. Let’s change the onCreate() method of application.

public class TrackerActivity extends Activity {

    private static final int EXCELLENT_LEVEL = 75;

    private static final int GOOD_LEVEL = 50;

    private static final int MODERATE_LEVEL = 25;

    private static final int WEAK_LEVEL = 0;


    public void onCreate(Bundle savedInstanceState) {







The R.layout.activity_tracker calls xml file and decodes it. Now you need to write the code for startSignalLevelListener() method. In this method you access TELEPHPONY_SERVICE using getSystemService(TELEPHONY_SERVICE) and starts the listener for phone state change.

private void startSignalLevelListener()  {

    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

    int events = PhoneStateListener.LISTEN_SIGNAL_STRENGTH |


    tm.listen(phoneStateListener, events);


Now you need to write the code for phoneStateListener. The phoneStateListener listens for internet connection state change and displays the internet connection state in a TextView that you defined in XML file. It will also listen for network signal strength change.

private final PhoneStateListener phoneStateListener = new PhoneStateListener() {


    public void onDataConnectionStateChanged(int state) {

        String connectionState = “Unknown”;

        switch(state)  {

            case TelephonyManager.DATA_CONNECTED: connectionState = “Connected”; break;

            case TelephonyManager.DATA_CONNECTING: connectionState = “Connecting”; break;

            case TelephonyManager.DATA_DISCONNECTED: connectionState = “Disconnected”; break;

            case TelephonyManager.DATA_SUSPENDED: connectionState = “Suspended”; break;

            default: connectionState = “Unknown: “ + state; break;






    publicvoid onSignalStrengthChanged(int asu) {






Now you need to write the code for setSignalLevel() and dataUsageInfo() methods. This methods will display the signal level status and data usage information in the screen.

private void setSignalLevel(int level) {

    int progress = (int) ((((float)level)/31.0) * 100);

     String signalLevelString = getSignalLevelString(progress);




private String getSignalLevelString(int level) {

    String signalLevelString = “Weak”;

    if(level > EXCELLENT_LEVEL) {

         signalLevelString = “Excellent”;


    elseif(level > GOOD_LEVEL) {

         signalLevelString = “Good”;


    elseif(level > MODERATE_LEVEL) {

         signalLevelString = “Moderate”;


    elseif(level > WEAK_LEVEL) {

         signalLevelString = “Weak”;


    return signalLevelString;


public void dataUsageInfo() {

     String info = “”;

     info += “\nMobile Interface:\n”;

     info += (“\tReceived: “ + TrafficStats.getMobileRxBytes() + ” bytes \n”);

     info += (“\tTransmitted: “ + TrafficStats.getMobileTxBytes() + ” bytes\n”);

     info += “\nAll Network Interface:\n”;

     info += (“\tReceived: “ + TrafficStats.getTotalRxBytes() + ” bytes \n”);

     info += (“\tTransmitted: “ + TrafficStats.getTotalTxBytes() + ” bytes “);



Now you can define onPause(), onResume() and onDestroy() methods. OnPause() method is called when you press the back button or home button. OnResume() method is called when you return to the application. OnDestroy() method is called when you exit from the application. When you are not using the listener, you have to free the listener for other applications using stopListening() function.


protectedvoid onPause() {





protectedvoid onResume() {






protectedvoid onDestroy() {




private void stopListening() {

     TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

     tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);



How To Run Android Application ?

That’s all the work related with the coding part. Now you can run your application in Android Virtual device(AVD) or android phone. To use an android vitual device you have to create it in AVD manager. To create an AVD :

  • Choose window->AVD Manager.
  • Click New and enter the following details in the new pop up dialog box as shown in picture and click Create AVD when you are done.


Press Ctrl+F11 or click the Run icon in Eclipse to run your application. To run the application in android device:

  • Enable USB debugging mode in the device settings and connect android device with computer using USB cable.
  • Press Ctrl+F11 or click the Run icon in Eclipse to run your application.


Data Usage Tracker Screenshot


It is always better to test and run your application in orginal android device than virtual device.