Thursday, 29 December 2011

Shortcut Keys for Eclipse

             The Shortcut keys are very useful for  programmers to  Developing Application easily and fast. You want to see Shortcut keys  in Eclipse.  Press  Ctrl+Shift+L  It will show Shortcut keys as follows.


Tuesday, 20 December 2011

Home Screen Widgets In Android

For Widget Creation Follow the Bellow Steps:

1.Create New Project.
2.Create One Folder in res as   res/xml .
3.Create One .xml file as AppWidgetProvider  in xml folder  like res/xml/widgmail.xml
4.Create  one .java file in src/   with Extention of  AppWidgetProvider.
5.Open manifest file Add some code as follows.

Step 1:

Now , We Create One project as follows.

Project Name          : Widget For Gmail.
ApplicationName    :WidgetForGmail.
Package Name
Acticity                      : WidgetForGmailActivity.
miniSDK Vertion      : 8

Step 2: Create one Folder named as xml in res/

Step 3: Create one xml file in xml folder as AppWidgetProvider named as widgmail.xml as follows

Then Click On thi Finish Button, and the write the following  code in widgmail.xml file 

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

Then Open The main.xml file write the following code:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

Step 4:Create  one .java file in src/   with Extention of  AppWidgetProvider, then write the following code in file as follows.



import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

public class WidGmail extends AppWidgetProvider {

      public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                  int[] appWidgetIds) {

            final int N = appWidgetIds.length;
            // Log.i("ExampleWidget","Updating widgets " +
            // Arrays.asList(appWidgetIds));

            for (int i = 0; i < N; i++) {
                  int appWidgetId = appWidgetIds[i];
                  // Create an Intent to launch ExampleActivity

                  Intent intent = new Intent(context, WidgetForGmailActivity.class);
                  PendingIntent p = PendingIntent.getActivity(context, 0, intent, 0);
                  RemoteViews views = new RemoteViews(context.getPackageName(),
                  views.setOnClickPendingIntent(, p);

                  // TODO Auto-generated method stub
                  appWidgetManager.updateAppWidget(appWidgetId, views);

Step 5:

The Open the  WidgetForGmailActivity .java file  write the following code


import android.content.Intent;
import android.os.Bundle;

public class WidgetForGmailActivity extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
       // setContentView(R.layout.main);
        Uri uri = Uri.parse("");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);

Step 6:  Now , Open the androidmanifest.xml file write the following code.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
      package="" android:versionCode="1" android:versionName="1.0">
      <uses-sdk android:minSdkVersion="8" />

      <application android:icon="@drawable/gmai" android:label="@string/app_name">
            <activity android:name=".WidgetForGmailActivity"
                        <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />
            <receiver android:name=".WidGmail" android:label="Gmail">
                        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                  <meta-data android:name="android.appwidget.provider"
                        android:resource="@xml/widgmail" />


Then Run the Application ,and perform long press on Home screen ,It appear one window, In This Window you Select Widgets and then Select Gmail Widget.
finally One Gmail icon is appear in Home Screen.

if you will click on that icon it will open Gamil login page. 

Wednesday, 16 November 2011

Android Adapters


An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.

An AdapterView is a view whose children are determined by an Adapter.

Some examples of AdapterViews are ListView, GridView, Spinner and Gallery.

There are several types or sub-classes of Adapter:

ListAdapter: Extended Adapter that is the bridge between a ListView and the data that backs the list. Frequently that data comes from a Cursor, but that is not required. The ListView can display any data provided that it is wrapped in a ListAdapter.

ArrayAdapter: A ListAdapter that manages a ListView backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView.


package com.project.ListView;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewActivity extends Activity implements OnItemClickListener {
      ListView listview;
      ArrayAdapter<?> aa;
      String[] list2 = { "murali", "Android", "technology", "java" };

      public void onCreate(Bundle savedInstanceState) {

            listview = (ListView) findViewById(;

            aa = new ArrayAdapter<String>(getApplicationContext(),
                        android.R.layout.simple_list_item_1, list2);

            listview.setOnItemClickListener(new OnItemClickListener() {

                  public void onItemClick(AdapterView<?> arg0, View arg1,
                              int position, long arg3) {
                        // TODO Auto-generated method stub
                                    "Clicked At " + position, 1).show();

      public void onItemClick(AdapterView<?> AA, View list, int position,
                  long arg3) {
            // TODO Auto-generated method stub



CursorAdapter: Adapter that exposes data from a Cursor to a ListView widget. The Cursor must include a column named "_id" or this class will not work.

HeaderViewListAdapter: ListAdapter used when a ListView has header views. This ListAdapter wraps another one and also keeps track of the header views and their associated data objects.

This is intended as a base class; you will probably not need to use this class directly in your own code.

ResourceCursorAdapter: An easy adapter that creates views defined in an XML file. You can specify the XML file that defines the appearance of the views.

SimpleAdapter: An easy adapter to map static data to views defined in an XML file. You can specify the data backing the list as an ArrayList of Maps. Each entry in the ArrayList corresponds to one row in the list.

// get messages from service
      ArrayList smsMessages = service.getSmsCalls();
      // initialize the List of Maps
      List<map>&gt; list = new ArrayList<map>&gt;();
      // iterate over all messages
      // create a map for each message
      // fill the map with data
      for (Call c: smsMessages) {
            Map map = new HashMap();
            map.put("number", c.getTo());
            map.put("date", DateParser.getTimeString(c.getBegin()));
            map.put("price", "€ " + c.getPrice());
      // the from array specifies which keys from the map
      // we want to view in our ListView
      String[] from = {"number", "date", "price"};
      // the to array specifies the TextViews from the xml layout
      // on which we want to display the values defined in the from array
      int[] to = {,,};
      // get a reference to the ListView
      ListView lv = (ListView)findViewById(;
      // create the adapter and assign it to the listview
   SimpleAdapter adapter = new SimpleAdapter(this.getApplicationContext(), list, R.layout.callog_detail_sms, from, to);


SimpleCursorAdapter: An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want, which views you want to display the columns, and the XML file that defines the appearance of these views.

SpinnerAdapter: Extended Adapter that is the bridge between a Spinner and its data. A spinner adapter allows to define two different views: one that shows the data in the spinner itself and one that shows the data in the drop down list when the spinner is pressed.

WrapperListAdapter: List adapter that wraps another list adapter. The wrapped adapter can be retrieved by calling getWrappedAdapter().

Itroduction To Android

What is android ?
                Android is a software stack for mobile devices that includes an operating system, middleware and key applications.

        One of the most widely used mobile OS these days is ANDROID. Android is a software bunch comprising not only operating system but also middleware and key applications. Android Inc was founded in Palo Alto of California, U.S. by Andy Rubin, Rich miner, Nick sears and Chris White in 2003. which is later on purchased by Google in 2005. Presently, Google and Open handset alliance are owners of Android operating system.  After original release there have been number of updates in the original version of Android.

               Android is a powerful Operating System supporting a large number of applications in Smart Phones. These applications make life more comfortable and advanced for the users. Hardwares that support Android are mainly based on ARM architecture platform. Some of the current features and specifications of android are:

Features in Android:

Technical overview to Android

Android is feature rich operating system for the mobile devices, which is developed by utilizing various programming languages,databases, frameworks, Libraries. This multipurpose operating system can be used in various mobile devices like netbooks, tablet computers and obviously in cellular phones. Giving a technical view that reveals an amazing fact of 12 million lines of code such as the programming languages in its coding are 2.8 million lines of C, Java holds 2.1 million lines and C++ with 1.75 million lines. The relational database management system SQLite is used for data storing. Android operating system software stack is composed of Java libraries, C libraries, SGL graphic engine, Webkit layout engine, Bionic libc, OpenGL ES 2.0 3D graphics API and SSL. There are various features for the Android handset user as well as Android developer / programmer. Few very common features are:
    • 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 (hardware acceleration optional)
    • SQLite for structured data storage
    • Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
    • GSM Telephony (hardware dependent)
    • Bluetooth, EDGE, 3G, and WiFi (hardware dependent)
    • Camera, GPS, compass, and accelerometer (hardware dependent)
    • Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE

Android comes with an Android market which is an online software store. It was developed by Google. It allows Android users to select, and download applications developed by third party developers and use them. There are around 2.0 lack+ games, application and widgets available on the market for users.

Android applications are written in java programming language. Android is available as open source for developers to develop applications which can be further used for selling in android market. There are around 200000 applications developed for android with over 3 billion+ downloads. Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. For software development, Android provides Android SDK (Software development kit).


These are the basics of Android applications:
•      Android applications are composed of one or more application components (activities, services, content providers, and broadcast receivers)
•      Each component performs a different role in the overall application behavior, and each one can be activated individually (even by other applications)
•      The manifest file must declare all components in the application and should also declare all application requirements, such as the minimum version of Android required and any hardware configurations required
•      Non-code application resources (images, strings, layout files, etc.) should include alternatives for different device configurations (such as different strings for different languages)

Google, for software development and application development, had launched two competitions ADC1 and ADC2 for the most innovative applications for Android. It offered prizes of USD 10 million combined in ADC1 and 2. ADC1 was launched in January 2008 and ADC 2 was launched in May 2009. These competitions helped Google a lot in making Android better, more user friendly, advanced and interactive.

Other Mobile Operating Systems:

There are different other Mobile operating systems also present in market in competition with Android. Apple's iOS and Windows Phone give strong competition to Android. A simple comparison between features and specifications of latest version of Android and other Operating Systems can be seen in the table given below.

According to Canalys, In Q2 2009 Android had 2.8% market share which had grown to 33% market share by Q4 2010 which made Android leader of smart phone OSs worldwide. The market share for commonly used mobile OSs is shown in the following pie chart.

     A large no of mobile companies are using Android. A list of companies supporting Android in their hardware is:
·         Acer Inc
·         ALCATEL ( TCL corporation )
·         Bluelans Communications
·         NCE casio Mobile Communications
·         Cherry Mobile
·         CSL
·         Dell
·         Garmin
·         Geeks Phone
·         General Mobile
·         High screen
·         HKC
·         HTC coroporation
·         Huawei
·         I-mobile
·         Lenovo
·         LG
·         Motorola
·         Samsung
·         Sony Ericsson
·         Videocon
·         ZTE

Platform like J2SE to development J2ME apps
Operating System with customized Java API to develop mobile apps
Kilobyte Virtual Machine (KVM)
Dalvik Virtual Machine (DVM)
Limited access to the native OS
Full access to the native OS
Limited GUI components
Many more and complex GUI components
Not easy to integrate with 3rd party applications
Has easy integration to Google's cloud services (GTalk, Maps, Gmail…)


Components of Android are:
         1. Activities
         2. Services
         3. Broadcast Receivers
         4. Content Providers.

          Activity is the basic building block of every visible android application. It provides the means to render a UI. Every screen in an application is an activity by itself. Though they work together to present an application sequence, each activity is an independent entity.

        Service is another building block of android applications which does not provide a UI. It is a program that can run in the background for an indefinite period.

          Broadcast Receiver is yet another type of component that can receive and respond to any broadcast announcements. 

          Content Providers are a separate league of components that expose a specific set of data to applications.

are messages that are passed between components. Intent is a bundle of information, a passive data structure that holds an abstract description of the operation to be performed.
    • Intent is a bundle of information, a passive data structure that holds an abstract description of the operation to be performed. (or in the case of broadcasts, a description of an event that has happened and is being announced).
NOTE: Intents can be made to work exactly like API calls by using what are called explicit intents, which will be explained later. But more often than not, implicit intents are the way to go and that is what is explained here.