The HTC mobile phone implemented Android in its HTC .... 2010). This windows phone was relased globally in 2011. It is a closed source and proprietary item.
1
CHAPTER 1
Introduction to Android
2
Introduction to Android
1.1 About Android Android is an operating System based on Linux operating system. It is meant for mobile phones and tablet computers. The development of Android is supported by Open Handset Alliance (OHA) a group of (86) hardware, software and telecommunication companies. Google leads the OHA and released the Android 1.0 in 2008. The HTC mobile phone implemented Android in its HTC Dream model for the first time. All versions of Android are named after a desert or a sweet. Each one is arranged in alphabetical order. The versions released so far are (June 2012): Version
Name
1.0 1.5 1.6 2.0 2.2.x 2.3.x 3.x 4.0.x 4.1
Android (September, 2008) Cupcake (April, 2009) Do nut (September, 2009) Eclair (October, 2009) Froyo (May, 2010) Gingerbread (December, 2010) Honeycomb (February, 2011) IceCream Sandwich (October, 2011) Jelly Bean (June, 2012)
Android is an open source software.
1.2
Android Platform
Android is a multiuser operating system is based on Linux Kernel. It has rich user interface(UI), code libraries, application framework, end user applications and Dalvik Virtual Machine(DVM) as shown in Fig.1.1
Fig.1.1
Android platform
3 The major layers of Android are: 1. 2. 3. 4. 5.
Linux Kernel Libraries Android Runtime Application Framework User Application
Linux Kernel Android is built using Linux 2.6. It acts as an abstraction layer between the hardware and software lying above it. It provides services such as security, memory management, process management, file management system etc. The hardware device specific drivers such as audio drivers, bluetooth drivers, camera drivers etc. are implemented here. This enables variety of devices to be handled in Android. Libraries Code libraries written in C/C++ meant for various components of the Android system are kept here. These libraries can be accessed by applications developed by developers through application framework. Some of the code libraries are: Webkit
-
it is used for web browsing. used in iPhone.
SGL
-
Scalable Games Graphics.
OpenGL ES
-
It supports 3D libraries.
It is the same WebKit
Language,
that
supports
2D
Surface Manager -
It helps to display composite 2D and 3D graphics from multiple applications seamlessly.
Media Libraries
These libraries help to handle many audio, video and still images. Few of the file formats handled are MPEG4, H.264, MP3, AAC, AMR, JPG and PNG.
-
LibC
-
A set of C libraries.
Free Type
-
These libraries help to render bitmap and vector type images.
SQLite
-
A lightweight database engine.
SSL
-
Secure Socket Layer.
4
Introduction to Android
Android Runtime Android consists of Dalvik Virtual Machine(DVM) and Core Java libraries. The Core libraries are similar to that of the core libraries of Java Programming language. These libraries are different from J2SE but provide the same functionalities of J2SE libraries. DVM is similar to JVM (Java Virtual Machine). First the Java class byte codes are converted to a form that can be executed more efficiently with low memory than the Java byte codes. The transofrmed code is called Dalvik Executable (dex) format. The DVM executes these dex files. DVM can handle multiple VM, each different from another.
Application Framework Application framework provide several services to the applications that an user develops. The applications you develop directly interact with these blocks. These framework blocks provide all the tools to access the functions of a phone. The application framework is designed to reuse the components. Any application can publish its capabilities and any other application can make use of these capabilities. Some important components in the Application Framework are: Activity Manager
-
It manages the lifecycle of application
Content Providers
-
It manages data sharing among applications
View System
-
IT provides extensive set of views that can be used to build an application with lists, grids, text boxes, buttons etc.
Telephony Manager
-
It manages all voice calls
Resource Manager
-
It provides access to non-code resources like locaized strings, graphics and layout files.
Location Manager
-
It provides location management using GPRS or Cell tower.
Notification Manager -
It helps application to display custom alerts in the status bar.
Applications The top layer of Android is the application layer. In this layer only all the applications run. Android comes with some built-in core applications like email client, SMS program, calendar, maps, web browser, location finder etc. All applications are written using Java programming language. A developer can develop their own application and run it in this layer. There is no distinction
5 between the built-in applications and the one developed by the developer. Applications can access all features of the Android.
1.3 Other Mobile Operating Systems Phones that run with Android or similar OS are called smart phones. Similar to Android, there are other mobile OS available in the market. Few of them are iOS
-
Used in iPhone from Apple Company. closed source and proprietary item.
It is a
Symbian
-
It is from Accenture, used in Nokia phones. a Open source.
Blackberry
-
Developed by Research In Motion (RIM). It was released in 1999. Used in Blackberry phones. It is closed source and proprietary item.
Windows Phone
-
This OS is developed by Microsoft. Earlier it was called Pocket PC(2002) and Windows Mobile (till 2010). This windows phone was relased globally in 2011. It is a closed source and proprietary item.
bada
-
It is developed by Samsung Electronics. It was released in May 2010. It is a closed source and proprietary item.
WebOs
-
It is developed by HP. It is based on Linux Kernel. It is a closed source and proprietary item.
GridOs
-
It is developed by Fusion Garage Android Kernel.
Mey Project
-
It is an open source, community driven OS.
SHR
-
It is an open source developed by Community.
MeeGo
-
It is developed by The Linux Foundation. open source.
Brew
-
It is developed by Qualcomm. It is a closed source proprietary item.
LiMo
-
It is developed by LiMo Foundation. source.
It is
It is based on
It is an
It is an open
6
Introduction to Android
As on June 2012, the market share for smart phone O.S are: Android iOS Blackberry Windows phone Others
-
61% 20.5% 6.0% 5.2% 7.2%
But these values differ from source to source.
1.4 Application Components Application components are the building blocks of an Android application. Each component is unique in its own and performs a specific role. Each has its own lifecycle. An Android application may contain one or more components. There are four components in an Android Application (Fig.1.2) They are : Activity Service Content Provider Broadcast Receivers (Intent) Android Application
Activity: Visual User Interface (UI)
Service: Has no UI. Runs in background (Eg. Playing music)
Broadcast Receiver: Has no UI. Receives and responds to broadcast announcements. Implemented in Intent Class
Content Provider: Makes data available to other applications through files and database SQLite
Fig.1.2
The Components of Android Applications
7
1.4.1 Activity An activity represents a user screen. It is the most common component used in an application. One application may have one or more activity. But each acivity is independent of the other. For example, an email application may have one activity for new emails, another activity to compose an e-mail and another activity for reading e-mails. All these three work together, but are independent of each other. Any other activity can access these activities, if it is permitted. Each of these activities will be implemented as a screen. Moving from one screen to another screen is done by starting a new activity. When a new screen appears, the previous screen is paused and put on to a stack. An activity is implemented as a subclass of Activity class and is defined in android.app Java package. The Activity employs one or more Views to display the actual screen to the user.
1.4.2 Services A Service is a program that runs in the background. It has no UI. Usually a Service is a long lived code. For example a media player playing sound files, is a service code. A service can be created by creating a subclass of the Service class defined in android.app Java package. One application can start a service and it can continue to run in the background even if the user switches to another application.
1.4.3 Content Provider A content provider is used to manage data used in one application and share it with other application running in the Android environment. An application can store data in a file, SQLite database, on the web, in XML file and access it. Using content provider other applications can query or even modify (if permitted) the data. A content provider is created by subclassing the ContentProvider class defined in android.content package. A schematic view of the functions of a content provider is shown in Fig.1.3.
8
Introduction to Android Application 2
Application 3
Activity 2.3
Activity 3.1
Application 1 Application 4
Activity 1.1 Content Provider A
Activity 1.3
File
Fig.1.3
SQLite
Activity 4.2
XML
Schematic view of a Content Provider in an Application
1.4.4 Broadcast Receivers Many activities in a phone are initiated by certain events happening in that phone. For example, ringing of a phone is an event. Receipt of a SMS is an event. When such events take place, these events should trigger the next event to take place. For example, when the SMS is received it must alert the user about the arrival of SMS. For this type of activity broadcast and broadcast receiver mechanism is used. The notification about the happening of an event by the Android system to other components of Android system is termed as broadcast (Fig.1.3). Broadcast receivers, receive these notifications and respond to it. Not only the Android system but also the application can also generate events. Broadcast receiver may not create an UI screen but they may create a status bar notification to alert the users. Broadcast receivers are gateway to other components of Android system. The broadcast receiver is implemented by subclassing BroadcastReceiver class defined in android.content package.
9 Register Event Source
(broadcast) Notification
Broadcast Receiver
(Through intent) Action
Fig.1.4
1.5
Broadcast Receiver Mechanism
Intents
An intent is an object containing the details of the message created by the components of the Android system. Usually an Intent is looking for a service or activity or broadcast receiver which meets its requirements. To help the Intent to identify the components that will provide the required activity, service or a broadcast receiver Intent filters are used. An Intent filter is an agent that contains the services, activities and broadcast receivers that are used in that application. It is here that applications are registered for listening events. The function of an Intent filter is to select the most appropriate item that meets the requirement of an Intent that has been dispatched by an Android component (Fig.1.5). Application 1 Intent or Event
Intent Filter startActivity (Intent) or startService (Intent) or sendBroadcast (events)
Service
Activity
Start-service (Intent)
Start-Activity (Intent)
Run Service
Show view
Broadcast-Receiver (Application) Broadcast Receive (Events)
Run Application
Fig.1.5 Intent Filter
10
Introduction to Android
The desired component, specified by the Intent object may lie in the same Android application or another application running in the Android system. Intents are two types: explicit and implicit. In implicit intents, the targets are not specifically mentioned. Based on the intent’s goal, the Intent filter selects the most appropriate service, activity or broadcast receiver. In explicit intents, the target component is specifically mentioned by its name. Intent filters are declared in the application’s AndroidManifest.XML file.
1.6 AndroidManifest File Every Android application must contain atleast one component among Activity, Service, BroadcastReceiver and ContentProvider. All components used in an application must be declared in the AndroidManifest.xml file, or simply manifest file. All the components declared for an application must be tied together so that the Android system can execute it. The manifest file integrate the components of the Android application. This file must be put at the root of the application project directory. A manifest file do few other additional functionalities such as: -
identify any user permission the application require, such as access to internet, access to the user’s contact etc.
-
declare the minimum API (application programming interface) level required by the application, based on which APIs the application function.
-
declare hardware and software features used or required by the application, such as camera, bluetooth service, touch screen.
-
API libraries the application needs to be linked, such as Google Maps Library.
An example for a AndroidManifest file is given in Listing 1.1 Listing 1.1 AndroidManifest.xml file for a simple application