Recently found by...
SnowCovered Top Sellers

Ultra Media Gallery is the most popular photo gallery and media gallery solution for DotNetNuke, UMG offers 10 different flash player to browse your gallery with completely different user interface experience.

Powerful, Ajax Enabled, Easy to Use. Document Management and Multimedia gallery functionality in one.Open-DocumentLibrary allows DotNetNuke users to organize share and manage documents, offering granular control over Folder and Document access.

Active Social is customizable social networking solution that fits the needs of a large company, small group, start-up business, or any size interest group. Connect with co-workers, people with similar interests, family, old friends, or meet new ones. Active Social provides a complete communication

Frustrated over the lack of customization for your user's registration fields? Dynamically setup your DNN Portal with custom registration fields, layout, questions, and other core integration options......

In this day and age, knowing as much detailed information as possible about your customer, prospect or web site user is essential. Thankfully, the new 'Dynamics Forms' module from Data Springs, makes it easier than ever to segment your data collection efforts.

Ultra Video Gallery is a brother product of Ultra Media Gallery, UVG allows you to upload videos in various format and automatically encode them to flv or H264 format, you also can add videos from internet and play them in our integrated flash video player.

One stop solution for events calendar and events registration! FREE DOWNLOAD is available now!

The amazing ANY COLOUR Flex2 skin + our unique EasyMod module allowing you to customise just about everything in this skin. DrNuke just re-wrote the rule book again.

The Future of Enterprise Search for DotNetNuke 3.x and 4.xOpen-SearchEngine provides DotNetNuke with a true enterprise search engine capable of indexing html content as well as documents from multiple sites and/or physical directories.

Capture your users attention, enrich your site with multimedia flash, and create and opt in distribution list for your DNN site. These are just a few of the many features the Data Springs Module Collection can provide you.

Recently Viewed...
DNN Modules
   
    |   Register   |   Sunday, March 14, 2010   
You are here:Resources  Articles & Information  Android SDK Example Application / Sample Code  


Creating your first Android application ...

 

A Brief Guide for

Creating your first

Android Application

 

Tip Calculator

 

 

 

 

 

 

 

 

 

Table of Contents

 

1 ) Welcome To Android - 3

2 ) System Requirements - 6

3 ) Downloads - 7

4 ) Creating a Dummy Application - 8

5 ) Writing Tip Calculator - 11

6 ) What’s Next - 20

 

 

 

 

 

 

 

 

 

Welcome to Android!

According to the official google release

“Android is a software stack for mobile devices that includes an operation system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.

Features :-

· Application Framework enabling reuse and replacement of components

· Dalvik virtual machine optimized for mobile devices

· Integrated browser based on the open source Webkit engine

· Optimized graphics powered by a custom 2D graphics library ; 3D graphics based on the OpenGL ES 1.0 specification

· SQLite for structured data storage

· Media support for common audio, video and still image formats

· GSM Telephony

· Bluetooth, EDGE, 3G and WIFI

· Camera, GPS, compass and accelerometer

· Rich development environment “

Android Architecture

The following picture shows the components of Android Operation System.

 

Applications

Android will ship with a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, and others. All applications are written using the Java programming language.

Application Framework

Developers have full access to the same framework APIs used by the core applications. The application architecture is designed to simplify the reuse of components; any application can publish its capabilities and any other application may then make use of those capabilities (subject to security constraints enforced by the framework). This same mechanism allows components to be replaced by the user.

Underlying all applications is a set of services and systems, including:

  • A rich and extensible set of Views that can be used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser
  • Content Providers that enable applications to access data from other applications (such as Contacts), or to share their own data
  • A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files
  • A Notification Manager that enables all applications to display custom alerts in the status bar
  • An Activity Manager that manages the life cycle of applications and provides a common navigation backstack

For more details and a walkthrough of an application, see below...

Libraries

Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework. Some of the core libraries are listed below:

  • System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices
  • Media Libraries - based on PacketVideo's OpenCORE; the libraries support playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG
  • Surface Manager - manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications
  • LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web view
  • SGL - the underlying 2D graphics engine
  • 3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer
  • FreeType - bitmap and vector font rendering
  • SQLite - a powerful and lightweight relational database engine available to all applications

Android Runtime

Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language.

Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool.

The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.

Linux Kernel

Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.

System Requirements

So rather than wasting time on learning the theoretical aspects we would rather like you to get your hands dirty and create your first app with Google Android.

But you need the following things ready with you before starting the development. This tutorial assumes that your OS is Windows XP but you can follow the procedure for other OS easily. Just download the relevant files from the download locations specified.

System and Software Requirements :-

To develop android app you need to have suitable environment as discussed below :-

Supported Operating Systems

· Windows XP or Vista

· Mac OS X 10.4.8 or later (x86 only)

· Linux (tested on Linux Ubuntu Dapper Drake)

 

Supported Development Environments:

  • Eclipse IDE
  • Other development environments or IDEs
    • JDK 5 or JDK 6 (JRE alone is not sufficient)
    • Apache Ant 1.6.5 or later for Linux and Mac, 1.7 or later for Windows
    • Not compatible with Gnu Compiler for Java (gcj)

\

Downloads and Development Settings

1 ) Download the google android sdk from http://code.google.com/android/download.html

And unzip the files into c:\tools\android

2 ) Download Ant from http://ant.apache.org/bindownload.cgi

And unzip the files into c:\tools\ant

3 ) Download JDK from http://java.sun.com/javase/downloads/index.jsp

And install it on c:\tools\java

4 ) Download DroidDraw from http://code.google.com/p/droiddraw/ ( Not Necessary but it will be easier to create the GUI using this ) and unzip the files into c:\tools\droiddraw

5) Create two environment variables ANT_HOME and JAVA_HOME and point them to c:\tools\ant and c:\tools\java respectively. Also add c:\tools\ant\bin & c:\tools\java\bin into your path variable.

You can create the variables by right clicking on My Computer -> Properties -> Advanced -> Environment Variables.

Be careful when you are editing your path. You should add the paths at the end of already existing path value by separating the paths with ;

Creating A Dummy Application

Please follow this steps and you will have a simple google android app which will print the message “Hello, World” on your mobile screen.

1 ) Run emulator.exe ( c:\tools\android\tools)

You should have the default screen visible. Keep the emulator running and goto Command Prompt and enter the following commands to create and upload dummy android app to our dummy phone.

c:\tools\android\tools>activitycreator.bat --out tipcalc com.android.tipcalc

c:\tools\android\tools>cd tipcalc

c:\tools\android\tools\tipcalc>ant

c:\tools\android\tools\tipcalc>..\adb install bin\tipcalc-debug.apk

  • The activitycreator.bat file will create all the basic stub files needed to create a basic android app.
  • Ant will compile the program created by activity creator into binary format which can be run on android phone.
  • Adb install will upload the binary application on the phone.

This is how your screen should look like :-

Now a simple android app has been created, compiled and uploaded onto our phone emulator. You can go and run that app. It should greet you with the famous “Hello, World “ Message.

Now we will modify this sample app and create our tip calculating application.

Don’t forget to delete the uploaded app before installing new app. It is necessary to delete the uploaded app. You can delete it by running this commands.

c:\tools\android\tools\tipcalc>..\adb shell

#cd data/app

#rm com.android.apk

#exit

You can use ls command to have a look at the app installed by user.

Writing Tip Calculator

Now we will create a simple tip calculating application very similar to one over here http://www.onlineconversion.com/tip_calculator.htm

First we will design our GUI. You can use droiddraw to design the gui.

The droiddraw will generate xml code. You have to replace the code in tipcalc\res\layout\main.xml with the generated code.

Old main.xml file contents :-

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Hello World, tipcalc"

/>

</LinearLayout>

New main.xml file contents :-

<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout

android:id="@+id/widget0"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

xmlns:android="http://schemas.android.com/apk/res/android"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Hello World, tipcalc"

/>

<TextView

android:id="@+id/widget28"

android:layout_width="99px"

android:layout_height="17px"

android:text="Amount of Bill"

android:layout_x="40px"

android:layout_y="32px"

>

</TextView>

<TextView

android:id="@+id/widget29"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Percentage to Tip"

android:layout_x="40px"

android:layout_y="82px"

>

</TextView>

<TextView

android:id="@+id/widget30"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Number of People"

android:layout_x="40px"

android:layout_y="132px"

>

</TextView>

<TextView

android:id="@+id/widget31"

android:layout_width="wrap_content"

android:layout_height="18px"

android:text="Tip Amout"

android:layout_x="40px"

android:layout_y="262px"

>

</TextView>

<TextView

android:id="@+id/widget32"

android:layout_width="wrap_content"

android:layout_height="18px"

android:text="Total Per Person"

android:layout_x="40px"

android:layout_y="352px"

>

</TextView>

<TextView

android:id="@+id/widget33"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Total To Pay"

android:layout_x="40px"

android:layout_y="302px"

>

</TextView>

<Button

android:id="@+id/btncalculate"

android:layout_width="87px"

android:layout_height="wrap_content"

android:text="Calculate"

android:layout_x="40px"

android:layout_y="182px"

>

</Button>

<Button

android:id="@+id/btnreset"

android:layout_width="86px"

android:layout_height="wrap_content"

android:text="Reset"

android:layout_x="140px"

android:layout_y="182px"

>

</Button>

<EditText

android:id="@+id/txtbillamount"

android:layout_width="wrap_content"

android:layout_height="35px"

android:text="100"

android:textSize="18sp"

android:layout_x="200px"

android:layout_y="22px"

>

</EditText>

<EditText

android:id="@+id/txtpercentage"

android:layout_width="51px"

android:layout_height="36px"

android:text="10"

android:textSize="18sp"

android:layout_x="200px"

android:layout_y="72px"

>

</EditText>

<EditText

android:id="@+id/txtpeople"

android:layout_width="wrap_content"

android:layout_height="39px"

android:text="1"

android:textSize="18sp"

android:layout_x="200px"

android:layout_y="122px"

>

</EditText>

<TextView

android:id="@+id/txttipamount"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text=""

android:layout_x="200px"

android:layout_y="262px"

>

</TextView>

<TextView

android:id="@+id/txttotal"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text=""

android:layout_x="200px"

android:layout_y="302px"

>

</TextView>

<TextView

android:id="@+id/txtperperson"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text=""

android:layout_x="200px"

android:layout_y="352px"

>

</TextView>

</AbsoluteLayout>

Now we will also write the program which will use this GUI to create the tip calculation functionality. In the tipcalc\src\com\android\tipcalc.java file you will find this code ( which was automatically created by activitycreator.bat .

Old tipcalc.java contents :-

package com.android;

import android.app.Activity;

import android.os.Bundle;

public class tipcalc extends Activity

{

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

}

Replace the above code with the following code .

New tipcalc.java contents :-

package com.android;

import android.app.Activity;

import android.os.Bundle;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Button;

import android.view.View;

public class tipcalc extends Activity

{

private EditText txtbillamount;

private EditText txtpeople;

private EditText txtpercentage;

private TextView txtperperson;

private TextView txttipamount;

private TextView txttotal;

private Button btncalculate;

private Button btnreset;

private double billamount = 0;

private double percentage = 0;

private double numofpeople=0;

private double tipamount = 0;

private double totaltopay = 0;

private double perperson = 0;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

initControls();

}

private void initControls()

{

txtbillamount = (EditText)findViewById(R.id.txtbillamount);

txtpeople = (EditText)findViewById(R.id.txtpeople);

txtpercentage = (EditText)findViewById(R.id.txtpercentage);

txtperperson=(TextView)findViewById(R.id.txtperperson);

txttipamount=(TextView)findViewById(R.id.txttipamount);

txttotal=(TextView)findViewById(R.id.txttotal);

btncalculate = (Button)findViewById(R.id.btncalculate);

btnreset = (Button)findViewById(R.id.btnreset);

btncalculate.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ calculate(); }});

btnreset.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ reset(); }});

}

private void calculate()

{

billamount=Double.parseDouble(txtbillamount.getText().toString());

percentage=Double.parseDouble(txtpercentage.getText().toString());

numofpeople=Double.parseDouble(txtpeople.getText().toString());

tipamount=(billamount*percentage)/100;

totaltopay=billamount+tipamount;

perperson=totaltopay/numofpeople;

txttipamount.setText(Double.toString(tipamount));

txttotal.setText(Double.toString(totaltopay));

txtperperson.setText(Double.toString(perperson));

}

private void reset()

{

txtbillamount.setText("");

txtpeople.setText("");

txtpercentage.setText("");

txtperperson.setText("");

txttipamount.setText("");

txttotal.setText("");

}

}

Now we will add an icon for our app.

Modify AndroidManifest.xml so that this line is changed from

<application android:label="@string/app_name">

To

<application android:icon="@drawable/icon" android:label="@string/app_name">

Now create a directory drawable in tipcalc\res and put icon.png file there.

Now compile our new application again by running

C:\tools\android\tools\tipcalc>ant

Upload the app to the emulator using adb install command and your first google android app is ready for launch.

Don’t forget to remove the previous uploaded application first.

In Action

What’s Next

 

So your first android application is now running successfully on the emulator. You should go through the documents provided along with the SDK to learn more about android. There are also few sample applications provided ( in samples ) directory. Compile them, upload them and try to understand them. Initially try modifying few things here and there and once you feel confident you can start with full-fledged development.

You should also go through online forums and learn from others.

Hopefully you will be creating great android apps in near future.

Don’t forget to share them with us.

Wishing you Good Luck.

 

 

Download Article Source Code Below (Must be registered user, registration is free!)

 

 

Feedback Comments
Records per Page
Page 1 of 5First   Previous   [1]  2  3  4  5  Next   Last   
chetan         3/12/2010 3:52:38 AM
download sample applicaiton Need sample application code for android Submitted By: chetan

Ankit Sharma         3/11/2010 8:22:43 PM
require to know how to install android in asp.net Please provide me the steps to configure android and iphone in asp.net thanking you for the same . regards, Ankit Submitted By: Ankit Sharma

rajnikanth         3/5/2010 12:55:29 PM
go..on... its goog and heplful 4 m. thankq... Submitted By: rajnikanth

reddyeswar         3/4/2010 8:02:56 PM
thanks It helps me a lot for further searching on various topics and if it provide some more examples it seems better Submitted By: reddyeswar

Paresh Mayani         3/3/2010 1:52:35 AM
Thanks This article shows the basic functionality of button and edittext box, so this is very good for beginners of android application development......... thanks you for such a good article............ Submitted By: Paresh Mayani

cnu         2/23/2010 8:59:28 AM
thnks thnk u so much........... Submitted By: cnu

cnu         2/23/2010 8:36:31 AM
thnks thnk u so much........... Submitted By: cnu

tanmai abc         2/23/2010 8:29:01 AM
thnks........ goodw work............. Submitted By: tanmai abc

Manjunatha         2/9/2010 12:26:55 AM
Android stick footer Hey i am doing health care application for the android device can you guys help me for the stick footer i need a stick footer i mean footer should always stick at the bottom Submitted By: Manjunatha

Shankar         1/29/2010 3:27:36 AM
Nice Its good one dude... wnat to know more about basic android and how it works Submitted By: Shankar

Feedback





Enter the code shown above in the box below
Send

 
DNN Modules
SharePoint Web Parts
Flash Image Rotator for SharePoint 2007

Dynamic Image Rotator Web Part for SharePoint 2007 

 

Who would have thought? Adobe Flash® with Sharepoint! The FIRST and ONLY image rotation web part for Sharepoint using Flash Technology from Adobe!  The Dynamic Image Rotator displays selected images and then rotates between the images. Several extended and optional features allow you to select the time to rotate each image, fade between i...more

Price: $129.99
 
Flash News Ticker for SharePoint 2007

Dynamic News Ticker Web Part for SharePoint 2007 

 

Provide current news items with a user-friendly news ticker for your Sharepoint Portal. With millions of web sites offering information you need a fun way to display information and the solution is Flash News Ticker....more

Price: $139.99
 
View Stock Quote Web Part

Stock Quote Web Part for SharePoint 2007

 

Giving your site visitors relevant information is critical. With the Data Springs Stock Web Part you can provide your users with up to date financial information....more

Price: $149.99
 
Random Image Web Part for SharePoint / MOSS 2007

Random Image Web Part for SharePoint 2007

With Random Image for Sharepoint 2007, you can select multiple images to display randomly when the web part loads...

Price: $139.99
 
SharePoint Charts Web Part

MOSS Charts Web Part for SharePoint 2007

The MOSS Chart Web Part is a web part built by Data Springs for the purpose of rendering several chart types based on data from a SharePoint list on a MOSS 2007 or WSS 3.0 Site ... more

Price: $269.99
 
Copyright 2005 - 2010 by Data Springs, Inc.
Contact Us | Terms Of Use | Privacy Statement