Unit I
Unit I
Introduction to Android
Syllabus:The Android 4.1 jelly Bean SDK, Understanding the Android Software Stack, installing the
Android SDK, Creating Android Virtual Devices, Creating the First Android Project, Using the Text
view Control, Using the Android Emulator, The Android Debug Bridge(ADB), Launching Android
Applications on a Handset.
INTRODUCTION
Android is a mobile operating system developed by Google, based on a modified version of
the Linux kernel and other open source software and designed primarily for touch screen mobile
devices such as smart phones and tablets. In addition, Google has further developed Android TV for
televisions, Android Auto for cars, and Wear OS for wrist watches, each with a specialized user
interface. Variants of Android are also used on game consoles, digital cameras, PCs and other
electronics.
The Android Operating System is a Linux-based OS developed by the Open Handset Alliance
(OHA). The Android OS was originally created by Android, Inc., which was bought by Google in
2005. Google teamed up with other companies to form the Open Handset Alliance (OHA), which has
become responsible for the continued development of the Android OS.
The android is a powerful operating system and it supports large number of applications in
Smart phones. These applications are more comfortable and advanced for the users. The hardware
that supports android software is based on ARM architecture platform. The android is an open source
operating system means that it’s free and any one can use it.
The android has got millions of apps available that can help you managing your life one or
other way and it is available low cost in market at that reasons android is verypopular.
Each time the OHA releases an Android version, it names the release after a dessert. Android
1.5 is known as Cupcake, 1.6 as Donut, 2.0/2.1 as Eclair, 2.2 as Froyo and 2.3 is dubbed Gingerbread
etc.
The Android OS is designed for phones. The important features of android are given below:
1) It is open-source.
2) Anyone can customize the Android Platform.
3) There are a lot of mobile applications that can be chosen by the consumer.
4) It provides many interesting features like weather details, opening screen, live RSS (Really Simple
Syndication) feeds etc.
5) It provides support for messaging services (SMS and MMS), web browser, storage (SQLite),
connectivity (GSM, CDMA, Blue Tooth, and Wi-Fi etc.), media, handset layout etc.
Page 1
Mobile Application Development Unit-I
Android Emulator:
The Emulator is a new application in android operating system. The emulator is a new prototype that
is used to develop and test android applications without using any physical device.
The android emulator has all of the hardware and software features like mobile device except phone
calls. It provides a variety of navigation and control keys. It also provides a screen to display your
application. The emulators utilize the android virtual device configurations. Once your application is
running on it, it can use services of the android platform to help other applications, access the
network, play audio, video, store and retrieve the data.
Android Versions
Google did not attach any high-calorie code name to its initial versions 1.0 and 1.1 of the Android
Operating System. The code names of android ranges from A to N currently, such as Aestro, Blender,
Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream Sandwitch, Jelly Bean, KitKat,
Lollipop and Marshmallow. Let's understand the android history in a sequence.
Page 2
Mobile Application Development Unit-I
Q 10.0 29
The Android 4.1 Jelly Bean SDK was released with new features for developers in July 2012. It
improves the beauty and simplicity of Android 4.0. A few of the big features of this release include
the following:
• Project Butter—Makes the Jelly Bean UI faster and more responsive. Also CPU Touch
Responsiveness is added, which increases CPU performance whenever the screen is touched. It uses
the finger’s speed and direction to predict where it will be located after some milliseconds, hence
making the navigation faster.
• Faster speech recognition—Speech recognition is now faster and doesn’t require any network to
convert voice into text. That is, users can dictate to the device without an Internet connection.
• Improved notification system— The notifications include pictures and lists along with text.
Notifications can be expanded or collapsed through a variety of gestures, and users can block
Page 3
Mobile Application Development Unit-I
notifications if desired. The notifications also include action buttons that enable users to call directly
from the notification menu rather replying to email.
• Supports new languages—Jelly Bean includes support for several languages including Arabic,
Hebrew, Hindi, and Thai. It also supports bidirectional text.
• Predictive keyboard—On the basis of the current context, the next word of the message is
automatically predicted.
• Auto-arranging Home screen—Icons and widgets automatically resize and realign as per the
existing space.
• Helpful for visually impaired users—The Gesture Mode combined with voice helps visually
impaired users to easily navigate the user interface.
• Improved Camera app—The Jelly Bean Camera app includes a new review mode of the captured
photos. Users can swipe in from the right of the screen to quickly view the captured photos. Also,
users can pinch to switch to a new film strip view, where they can swipe to delete photos.
• Better communication in Jelly Bean—Two devices can communicate with Near Field
Communication (NFC); that is, two NFC-enabled Android devices can be tapped to share data. Also,
Android devices can be paired to Bluetooth devices that support the Simple Secure Pairing standard
by just tapping them together.
• Improved Google Voice search—Jelly Bean is equipped with a question and answer search
method that helps in solving users’ queries similar to Apple’s popular Siri.
• Face Unlock—unlocks the device when the user looks at it. It also prevents the screen from
blacking out. Optionally “blink” can be used to confirm that a live person is unlocking the device
instead of a photo.
• Google Now—provides users “just the right information at just the right time.” It displays cards to
show desired information automatically. For example, the Places card displays nearby restaurants and
shops while moving; the Transit card displays information on the next train or bus when the user is
near a bus stop or railway station; the Sports card displays live scores or upcoming game events; the
Weather card displays the weather conditions at a user’s current location, and so on.
• Google Play Widgets—Provides quick and easy access to movies, games, magazines, and other
media on the device. It also suggests new purchases on Google Play.
• Faster Google Search—Google Search can be opened quickly, from the lock screen and from the
system bar by swiping up and also by tapping a hardware search key if it is available on the device.
• Supports antipiracy—This feature supports developers in the sense that the applications are
encrypted with a device-specific key making it difficult to copy and upload them to the Internet.
Page 4
Mobile Application Development Unit-I
The Android operating system is built on top of a modified Linux kernel. The software stack contains
Java applications running on top of a virtual machine. Components of the system are written in Java,
C, C++, and XML. Android operating system is a stack of software components which is roughly
divided into five sections
1) Linux kernel
2) Native libraries (middleware),
3) Android Runtime
4) Application Framework
5) Applications
1) Linux kernel
It is the heart of android architecture that exists at the root of android architecture. Linux kernel is
responsible for device drivers, power management, memory management, device management and
resource access. This layer is the foundation of the Android Platform.
Contains all low level drivers for various hardware components support.
Android Runtime relies on Linux Kernel for core system services like,
Memory, process management, threading etc.
Network stack
Driver model
Security and more.
Page 5
Mobile Application Development Unit-I
2) Libraries
On top of Linux kernel there is a set of libraries including open-source Web browser engine
WebKit, well known library libc, SQLite database which is a useful repository for storage and
sharing of application data, libraries to play and record audio and video, SSL libraries
responsible for Internet security etc.
SQLite Library used for data storage and light in terms of mobile memory footprints and
task execution.
WebKit Library mainly provides Web Browsing engine and a lot more related features.
The surface manager library is responsible for rendering windows and drawing surfaces
of various apps on the screen.
The media framework library provides media codecs for audio and video.
The OpenGl (Open Graphics Library) and SGL(Scalable Graphics Library) are the
graphics libraries for 3D and 2D rendering, respectively.
The FreeType Library is used for rendering fonts.
3) Android Runtime
In android runtime, there are core libraries and DVM (Dalvik Virtual Machine) which is
responsible to run android application. DVM is like JVM but it is optimized for mobile
devices. It consumes less memory and provides fast performance. The Dalvik VM makes use
of Linux core features like memory management and multi-threading, which is intrinsic in the
Java language. The Dalvik VM enables every Android application to run in its own process,
with its own instance of the Dalvik virtual machine.
4) Android Framework
On the top of Native libraries and android runtime, there is android framework. Android
framework includes Android API's such as UI (User Interface), telephony, resources,
locations, Content Providers (data) and package managers. It provides a lot of classes and
interfaces for android application development.
5) Applications
On the top of android framework, there are applications. All applications such as home,
contact, settings, games, browsers are using android framework that uses android runtime and
libraries. Android runtime and native libraries are using linuxkernal.
Page 6
Mobile Application Development Unit-I
You can likewise get Android Studio here. Again, get the latest version and remember that this
is also going to include the Android SDK and various other tools you need to get started.
It doesn’t really matter what order you install these elements in, but it makes sense to go ahead with
Java first — nothing else will work without it. Having Java on our computer when we install Android
Studio will also remove an extra step we’d otherwise have to go through. To get started, double click
on the JDK executable and click “Next” to go through the steps. Make a note of where the JDK is
installed, as this may come in handy in the future.
Installing Android Studio is just as simple. Once again, just run the setup file and then click “Next” to
progress through the stages. Make sure you tick the checkbox to install the Android SDK as well as
Studio. It is also a good idea to make a note of where everything is being installed in case you need it
later. By default, your app might go into AppData\Local, which is a hidden folder and can cause
confusion later on. If you change this to something easier to find, note that your directory isn’t
allowed to have any spaces in it.
Page 7
Mobile Application Development Unit-I
To name your new project, just click the top menu and select File > New > New Project. You’ll then
be asked to come up with a name for your application and to add a company domain as well. The
“package name” (the name of your app as the devices will see it) is made up of both these names. If
you have a business, use the domain name on which your site is hosted (which will help to identify
the app as yours). If not, don’t worry — you can put anything in here.
If you want to call your app “Welcome” and your business domain is “kvsw.in,” then you might end
up with a package name like “in.kvsw.Welcome” The only name that the user will ever see is
“Welcome.”
Page 8
Mobile Application Development Unit-I
Next, you’ll be asked what kind of device you’re developing for. The “Minimum SDK” is the lowest
version of Android you want to support.
Select the lower the Minimum SDK, the more users will be able to try and buy your apps. If your app
is going to rely on more modern features of Android Oreo for instance, you might be required to
target newer versions of Android exclusively.
While installing Android Studio, you likely installed the most recent and up-to-date version of the
Android SDK. Android SDKs are backward compatible, so you can support any version of Android
that is lower, but you’ll need to update it if you want to support something newer in future.
For now, just leave this as is, though you should remember to tick “phone and tablet.” If you wanted
to target watches or TV, then you would tick the respective boxes below, too.
On the next screen, you can add an activity. Apps are made of activities — generally speaking, they
are the screens you move between while using an app. Chances are you will begin your app with
some kind of splash screen or UI to show the user, so you may as well add an activity at this
stage. You can add activities later on, too.
Page 9
Mobile Application Development Unit-I
There are several options here though, which include “Basic Activity,” “Bottom Navigation
Activity,” “Empty Activity,” and more.
Click “Next” again and you’ll land on a screen where you can name your activity and the
accompanying layout file, which will handle the appearance of your app and the positions of the
elements. Activity files are written in Java and have the extension “.java,” while layout files use XML
and have the “.xml” extension. If you build a big app project, then you can eventually end up with
lots of different activities, all with different names. This can get confusing, so it’s important to name
them logically. If no activity in your app is considered the “main” screen, you might want to change
this and name it something different. For most people this is going to be just fine as it is!
Page
10
Mobile Application Development Unit-I
Your layout file will go into your resources folder, along with the images and sound effects you
create later on. Anything in this folder is required to use lower case only. That’s why the default
name for your xml is activity_main.xml, while the default name for your Java file
is MainActivity.java.
For now, you can leave these names as the defaults — Just hit “Next.” You should now be looking at
your very first app — congratulations!
Page
11
Mobile Application Development Unit-I
Google has already populated this project with some code for you, so it should already function as a
full “Hello World” app! If you were able to run it (which requires a little more set-up unfortunately!),
you would see “Hello World!” displayed on your screen. For now, if you double click on
the activity_main.xml file and then choose the “Design” view, you’ll be able to see what it would
look like.A whole lot of different files contribute to just that single “Hello World!,” as well as an
awful lot of buttons and tools.
Now that you’ve installed Android Studio and you know how to create your first app project, the first
crucial step in becoming an Android developer is over!
An Android Virtual Device (AVD) represents a device configuration. There are many
Android devices, each with different configuration. To test whether the Android application is
compatible with a set of Android devices, you can create AVDs that represent their configuration. For
example, you can create an AVD that represents an Android device running version 4.1 of the SDK
with a 64MB SD card. After creating AVDs, you point the emulator to each one when developing and
testing the application. AVDs are the easiest way of testing the application with various
configurations.
To create AVDs in Eclipse, select the Window, AVD Manager Option. An Android Virtual
Device Manager dialog opens, as shown in Figure. The dialog box displays a list of existing AVDs,
letting you create new AVDs and manage existing AVDs. Because you haven’t yet defined an AVD,
an empty list is displayed.
Page
12
Mobile Application Development Unit-I
Select the New button to define a new AVD. A Create new Android Virtual Device (AVD) dialog
box, appears The fields are as follows:
• Name—Used to specify the name of the AVD.
• Target—Used to specify the target API level. Our application will be tested against the specified
API level.
• CPU/ABI—Determines the processor that we want to emulate on our device.
• SD Card—Used for extending the storage capacity of the device. Large data files such as audio and
video for which the built-in flash memory is insufficient are stored on the SD card.
• Snapshot—Enable this option to avoid booting of the emulator and start it from the last saved
snapshot. Hence, this option is used to start the Android emulator quickly.
• Skin—Used for setting the screen size. Each built-in skin represents a specific screen size. You can
try multiple skins to see if your application works across different devices.
• Hardware—Used to set properties representing various optional hardware that may be present in
the target device.
Page
13
Mobile Application Development Unit-I
2) Provide the following information: Application name, Company domain, Project location and
Package name of application and click next.
Page
14
Mobile Application Development Unit-I
Page
15
Mobile Application Development Unit-I
After finishing the Activity configuration, Android Studio auto generates the activity class and other
required configuration files.
Now an android project has been created. You can explore the android project and see the simple
program, it looks like this:
Page
16
Mobile Application Development Unit-I
File: MainActivity.java
package first.javatpoint.com.welcome;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
To run the android application, click the run icon on the toolbar or simply press Shift + F10.
The android emulator might take 2 or 3 minutes to boot. So please have patience. After booting the
emulator, the android studio installs the application and launches the activity. You will see something
like this:
Page
18
Mobile Application Development Unit-I
Set any other attributes you desire to adjust the control’s appearance. For example, adjust the
text size, color, font or other style settings.
By default, text contents of a TextView control are left-aligned. However, you can position
the text using the gravity attribute. This setting positions your text relative to the control’s
overall width and height and only really makes sense to use if there is whitespace within the
TextView control.
In XML, this property would appear within your TextView control as:
android:gravity="center"
By default, the background of a TextView control is transparent. That is, whatever is behind
the control is shown. However, you can set the background of a control explicitly, to a color
resource, or a drawable (picture). In XML, this property would appear within your TextView
control as:
android:background="#0000ff"
By default, any text contents within a TextView control is displayed as plain text. However,
by setting one simple attribute called autoLink, all you can enable automatic detection of web,
email, phone and address information within the text. In XML, this property would appear
within your TextView control as:
android:autoLink="all"
You can control the color of the text within the TextView control by using the textColor
attribute. This attribute can be set to a color resource, or a specific color by hex value. In
XML, this property would appear within your TextView control as:
android:textColor="#ff0000"
You can control the style of the text (bold, italic) and font family (sans, serif, monospace)
within the TextView control by using the textStyle and typeface attributes. In XML, these
properties would appear within your TextView control as:
android:textStyle="bold"
android:typeface="monospace"
Example:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/ap
k/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="first.javatpoint.com.welcome.MainActivity">
Page
19
Mobile Application Development Unit-I
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:background="#00ffff"
android:textColor="#ff0000"
android:textStyle="bold"
android:typeface="monospace"
android:textSize="35dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
File: MainActivity.java
package first.javatpoint.com.welcome;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
To run the android application, click the run icon on the toolbar or simply press Shift + F10.
The android emulator might take 2 or 3 minutes to boot. So please have patience. After booting the
emulator, the android studio installs the application and launches the activity. You will see something
like this:
Page
20
Mobile Application Development Unit-I
The Android emulator is useful to test Android applications for compatibility with devices of
different configurations. But still, it is a piece of software and not an actual device and has several
limitations:
Emulators no doubt help in knowing how an application may operate within a given
environment, but they still don’t provide the actual environment to an application. For
example, an actual device has memory, CPU, or other physical limitations that an emulator
doesn’t reveal.
Emulators just simulate certain handset behavior. Features such as GPS, sensors, battery,
power settings, and network connectivity can be easily simulated on a computer.
SMS messages are also simulated and do not use a real network.
Phone calls cannot be placed or received but are simulated.
No support for device-attached headphones is available.
Peripherals such as camera/video capture are not fully functional.
No USB or Bluetooth support is available.
Page
21
Mobile Application Development Unit-I
The emulator provides some facilities too. You can use the mouse and keyboard to interact with the
emulator when it is running. For example, you can use your computer mouse to click, scroll, and drag
items on the emulator. You can also use it to simulate finger touch on the soft keyboard or a physical
emulator keyboard.
The tool is part of the Android SDK (Android Software Development Kit) and is located in the
subdirectory platform-tools. In previous versions of the SDK it was located in the subdirectory tools.
The Android Debug Bridge is a software interface between the device and the local computer, which
allows the direct communication of both components. This includes the possibility to transfer files
from one component to the other one, as well as executing commands from the computer on the
connected device. The ADB can be used through a command line window, terminal/shell in Linux-
based systems, a command line (cmd) for Windows. The main advantage is to execute commands on
the phone directly out of the computer, without any direct user interaction to the phone, which makes
especially debugging a lot easier.
A client, which sends commands. The client runs on your development machine. You can
invoke a client from a command-line terminal by issuing an adb command.
A daemon (adbd), which runs commands on a device. The daemon runs as a background
process on each device.
A server, which manages communication between the client and the daemon. The server runs
as a background process on your development machine.
When you start an adb client, the client first checks whether there is an adb server process already
running. If there isn't, it starts the server process. When the server starts, it binds to local TCP port
5037 and listens for commands sent from adb clients—all adb clients use port 5037 to communicate
with the adb server.
Page
22
Mobile Application Development Unit-I
The server then sets up connections to all running devices. It locates emulators by scanning odd-
numbered ports in the range 5555 to 5585, the range used by the first 16 emulators. Where the server
finds an adb daemon (adbd), it sets up a connection to that port. Note that each emulator uses a pair of
sequential ports — an even-numbered port for console connections and an odd-numbered port for adb
connections.
Once the server has set up connections to all devices, you can use adb commands to access those
devices. Because the server manages connections to devices and handles commands from multiple
adb clients, you can control any device from any client
Page
23