0% found this document useful (0 votes)
17 views52 pages

Android Mobile App Development Guide

The document provides an overview of Android as an open-source, Linux-based operating system for mobile devices, detailing its history, features, and architecture. It covers the installation of Android tools, the anatomy of an Android project, and the use of XML for user interface design. Additionally, it discusses the Android software stack, including the Linux kernel, native libraries, and application framework, emphasizing the unified approach to application development across various devices.

Uploaded by

prakash N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views52 pages

Android Mobile App Development Guide

The document provides an overview of Android as an open-source, Linux-based operating system for mobile devices, detailing its history, features, and architecture. It covers the installation of Android tools, the anatomy of an Android project, and the use of XML for user interface design. Additionally, it discusses the Android software stack, including the Linux kernel, native libraries, and application framework, emphasizing the unified approach to application development across various devices.

Uploaded by

prakash N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

18CST114-Mobile Application Development

Unit-I
UNIT- I INTRODUCTION AND INSTALLATION OF ANDROID TOOLS
Android Overview:

 Android is an open source and Linux-based Operating System for mobile devices such as smartphones
and tablet computers. Android was developed by the Open Handset Alliance, led by Google, and other
companies.

 Android offers a unified approach to application development for mobile devices which means developers
need only develop for Android, and their applications should be able to run on different devices powered
by Android.
History and Version of Android :

 The first beta version of the Android Software Development Kit (SDK) was released by Google in 2007

where as the first commercial version, Android 1.0, was released in September 2008.

 On June 27, 2012, at the Google I/O conference, Google announced the next Android version, 4.1 Jelly

Bean. Jelly Bean is an incremental update, with the primary aim of improving the user interface, both in

terms of functionality and performance.

 The source code for Android is available under free and open source software licenses. Google publishes

most of the code under the Apache License version 2.0 and the rest, Linux kernel changes, under the

GNU General Public License version 2.


Why Android ?
Features of Android
Beautiful UI
Android OS basic screen provides a beautiful and intuitive user interface.
Connectivity
GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC and WiMAX.
Storage
SQLite, a lightweight relational database, is used for data storage purposes.
Media support
H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1, MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP.
Messaging-SMS and MMS
Web browser
Based on the open-source WebKit layout engine, coupled with Chrome's V8 JavaScript engine supporting HTML5 and CSS3.
Multi-touch
Android has native support for multi-touch which was initially made available in handsets such as the HTC Hero.
Multi-tasking
User can jump from one task to another and same time various application can run simultaneously.
Resizable widgets
Widgets are resizable, so users can expand them to show more content or shrink them to save space.
Multi-Language
Supports single direction and bi-directional text.

GCM
Google Cloud Messaging (GCM) is a service that lets developers send short message data to their users on Android devices, without needing a proprietary sync solution.

Wi-Fi Direct
A technology that lets apps discover and pair directly, over a high-bandwidth peer-to-peer connection.
Android Beam
A popular NFC-based technology that lets users instantly share, just by touching two NFC-enabled phones together.
Android Applications

 Android applications are usually developed in the Java language using the Android Software Development

Kit.

 Once developed, Android applications can be packaged easily and sold out either through a store such as

Google Play, SlideME, Opera Mobile Store, Mobango, F-droid and the Amazon Appstore.

 Android powers hundreds of millions of mobile devices in more than 190 countries around the world. It's the

largest installed base of any mobile platform and growing fast. Every day more than 1 million new Android

devices are activated worldwide.

 This tutorial has been written with an aim to teach you how to develop and package Android application. We

will start from environment setup for Android application programming and then drill down to look into various

aspects of Android applications.


Categories of Android applications:
Android Flavors:
Android Stack

The Android software stack generally consists of a Linux kernel and a collection of C/C++ libraries that is exposed

through an application framework that provides services, and management of the applications and run time.

Android architecture is a stack of software components. It is in the form of a software application, operating system, run-

time environment, middleware, native libraries and services.

It is categorized into five parts as below:

1. Linux Kernel

2. Native Libraries

3. Android Runtime

4. Application Framework

5. Applications
1. Linux Kernel

Linux is the heart of Android architecture.

It provides a level of abstraction between the hardware devices and software applications.

The Android operating system is based on the Linux kernel.

The Linux kernel is responsible for various device drivers such as Camera driver, Display driver, Bluetooth

driver, Keypad driver, Memory management, Process management, Power management, etc.
2. Native Libraries

The native libraries such as Media, WebKit, SQLite, OpenGL, FreeType, C Runtime library (libc) etc. are

situated on the top of a Linux kernel.

Media library is responsible for playing and recording audio and video formats, FreeType is for font support,

WebKit is for browser support, SQLite is for database, SSL is for Internet security etc.
[Link] Runtime

 Android Runtime is the third section of the architecture and situated on the second layer from the

bottom.

 Android Runtime includes core libraries and Dalvik Virtual Machine (DVM) which is responsible to

run android application.

 Dalvik Virtual Machine (DVM) is like Java Virtual Machine (JVM) in Java, but DVM is optimized

for mobile Devices.

 DVM makes use of the Linux core features like memory management and multi-threading, which

are essential in the Java language.

 DVM provides fast performance and consumes less memory.


[Link] Framework

 Application framework is situated on the top of the Native libraries and Android [Link] framework provides

a lot of classes and interfaces for Android application development and higher level services to the applications in

the form of Java classes.

 It includes Android API's such as Activity manager, Window manager, Content Provider, Telephony Manager,

[Link] manger is responsible for controlling all the aspects of the application lifecycle and activity stack,

Content provider is responsible for allowing the applications to publish and share the data with the other

applications, View system is responsible for creating application user interfaces, etc.

5. Applications

 Applications are situated on the top of the Application [Link] applications such as Home, Contact, Alarm,

Calender, Camera, Browsers, etc. use the Android framework which uses Android runtime and libraries. Android

runtime and Native libraries use Linux [Link] user can write his/her application to be installed on this layer only.

 Android is an open source and Linux-based Operating System for mobile devices such as smartphones and tablet computers. Android was developed by the Open Handset Alliance, led by Google, and other companies.
 Android offers a unified approach to application development for mobile devices which means developers need only develop for Android, and their applications should be able to run on different devices powered by Android.
Hardware Abstraction Layer (HAL):

 A hardware abstraction layer (HAL) is an abstraction layer, implemented in software, between the

physical hardware of a computer and the software that runs on that computer.

 HAL can basically be considered to be the driver for the motherboard and allows instructions from

higher level computer languages to communicate with lower level components, but prevents direct

access to the hardware.


The HAL provides the following benefits:
 Enabling the OS to perform regardless of the hardware architecture
 Enabling device drivers to provide direct access to each hardware device, which allows programs to be
device-independent
 Allowing software programs to communicate with the hardware devices at a general level Facilitating
portability
Installation and Use of Android Tools:
Installing the Android SDK

It provides the following services to customers

[Link] libraries

[Link] tools

[Link] and debug operations

If you're a new Android developer, we recommend you download the ADT Bundle to quickly start developing

apps. It includes the essential Android SDK components and a version of the Eclipse IDE with built-in ADT

(Android Developer Tools) to streamline your Android app development.

With abysingle download, the ADT Bundle includes everything you need to begin developing apps
[Link]
[Link] Procedure
Eclipse IDE
[Link]

Windows 32-bit: [Link] 465 Mb


Windows 64-bit: adt-bundle-windows-x86_64-[Link] 465 Mb
Mac OS X 64-bit: adt-bundle-mac-x86_64-[Link] 430 Mb
Linux 32-bit(Ubuntu): [Link] 459 Mb
Linux 64-bit(Ubuntu): adt-bundle-linux-x86_64-[Link] 460 Mb

by [Link]
Installing the Android SDK

by [Link]
Installing the Android SDK

by [Link]
Installing the Android SDK

by [Link]
Installing the Android SDK
Anatomy of an Android Project :

The Anatomy of Android projects contains following four windows

[Link] Explorer

[Link] Window

[Link] window

[Link] window
Anatomy of an Android Project
Drawable Resources:

A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with

APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and

android:icon.

Example:

getDrawable(int)

android:drawable

android:icon.
There are several different types of drawables:
Bitmap File
A bitmap graphic file (.png, .jpg, or .gif). Creates a BitmapDrawable.
Nine-Patch File
A PNG file with stretchable regions to allow image resizing based on content (.[Link]). Creates a
NinePatchDrawable.
Layer List
A Drawable that manages an array of other Drawables. These are drawn in array order, so the element
with the largest index is be drawn on top. Creates a LayerDrawable.
State List
An XML file that references different bitmap graphics for different states (for example, to use a different
image when a button is pressed). Creates a StateListDrawable.
Level List
An XML file that defines a drawable that manages a number of alternate Drawables, each assigned a
maximum numerical value. Creates a LevelListDrawable.
Transition Drawable
An XML file that defines a drawable that can cross-fade between two drawable resources. Creates a
Inset Drawable

An XML file that defines a drawable that insets another drawable by a specified distance. This is useful when

a View needs a background drawble that is smaller than the View's actual bounds.

Scale Drawable

An XML file that defines a drawable that changes the size of another Drawable based on its current level

value. Creates a ScaleDrawable

Shape Drawable

An XML file that defines a geometric shape, including colors and gradients. Creates a ShapeDrawable.
Example:
Bitmap File
A bitmap file is a .png, .jpg, or .gif file. Android creates a Drawable resource for
any of these files when you save them in the res/drawable/ directory.
file location:
res/drawable/[Link] (.png, .jpg, or .gif)
The filename is used as the resource ID.
compiled resource datatype:
Resource pointer to a BitmapDrawable.
resource reference:
In Java: [Link]
Example:
example:
With an image saved at res/drawable/[Link], this layout XML
applies the image to a View:
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/myimage" />
The following application code retrieves the image as a Drawable:
Resources res = getResources();
XML Introduction:

• XML stands for eXtensible Markup Language


• XML is a markup language much like HTML
• XML was designed to store and transport data
• XML was designed to be self-descriptive
• XML is a W3C Recommendation
• The XML language has no predefined tags.
XML Declaration
XML - declaration is not a tag. It is used for the transmission of the meta-data of a document.
<?xml version="1.0" encoding="UTF-8"?>

Comments:
<!-- Comment -->

 The first beta version of the Android Software Development Kit (SDK) was released by Google in 2007 where as the first commercial version, Android 1.0, was released in September

2008.

 On June 27, 2012, at the Google I/O conference, Google announced the next Android version, 4.1 Jelly Bean. Jelly Bean is an incremental update, with the primary aim of improving

the user interface, both in terms of functionality and performance.

 The source code for Android is available under free and open source software licenses. Google publishes most of the code under the Apache License version 2.0 and the rest, Linux

kernel changes, under the GNU General Public License version 2.


Example:
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

 The first beta version of the Android Software Development Kit (SDK) was released by Google in 2007 where as the first commercial version, Android 1.0, was released in September 2008.

 On June 27, 2012, at the Google I/O conference, Google announced the next Android version, 4.1 Jelly Bean. Jelly Bean is an incremental update, with the primary aim of improving the user interface, both in terms of

functionality and performance.

 The source code for Android is available under free and open source software licenses. Google publishes most of the code under the Apache License version 2.0 and the rest, Linux kernel changes, under the GNU

General Public License version 2.


Example:
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Creating user interface using XML:
 The graphical user interface for an Android app is built using a hierarchy of View and ViewGroup objects.
 View objects are usually UI widgets such as buttons or text fields
 ViewGroup objects are invisible view containers that define how the child views are laid out, such as in a grid or a
vertical list.
Create a Linear Layout
 Open the activity_main.xml file from the res/layout/ directory.
 Note: In Eclipse, when you open a layout file, you’re first shown the Graphical Layout editor. This is
an editor that helps you build layouts using WYSIWYG tools. For this lesson, you’re going to work
directly with the XML, so click the activity_main.xml tab at the bottom of the screen to open the XML
editor.
 The BlankActivity template you chose when you created this project includes the activity_main.xml file
with a RelativeLayout root view and a TextView child view.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout>
Add a Text Field
 To create a user-editable text field, add an <EditText> element inside the <LinearLayout>.
 Like every View object, you must define certain XML attributes to specify the EditText
object's properties. Here’s how you should declare it inside the <LinearLayout> element:
<EditText android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />

 Every resource has a corresponding resource object defined in your project's gen/[Link]

file. You can use the object names in the R class to refer to your resources, such as when

you need to specify a string value for the android:hint attribute.


Add a Button

Now add a <Button> to the layout, immediately following the <EditText> element:

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/button_send" />

The height and width are set to "wrap_content" so the button is only as big as necessary to fit the button's text. This button

doesn't need the android:id attribute, because it won't be referenced from the activity code.
Overview of Android Building Blocks:
The building blocks or fundamental components of android are

1. Activities

2. Views

3. Intents

4. Services

5. content providers
Activity
An activity is a class that represents a single screen. It is like a Frame in AWT.
View
A view is the UI element such as button, label, text field etc. Anything that you see is a view

Intent
Intent is used to invoke components. It is mainly used to:

 Start the service

 Launch an activity

 Display a web page

 Display a list of contacts

 Broadcast a message

 Dial a phone call etc.


For example, you may write the following code to view the webpage.
Intent intent=new Intent(Intent.ACTION_VIEW);
[Link]([Link]("[Link]
startActivity(intent);
Intent
Service

 Service is a background process that can run for a long time.

 There are two types of services local and remote. Local service is accessed from within the application whereas

remote service is accessed remotely from other applications running on the same device.
Content Provider
Content Providers are used to share data between the applications

Fragment
Fragments are like parts of activity. An activity can display one or more fragments on the screen at the
same time.
Logging Messages in Android:

 LOG in a simple language can be defined as ”record of events”.

 In Android, Logging works as a diagnostic technique used by developers.

 It basically provides an insight of what’s happening in your application.

 We can write Log messages in the code with the help of LOG class and the messages get displayed

in the Logcat window on running the application.


With the help of LOG class you can write your custom log messages in the application. The log methods used are:

 Log.e display error messages.

 Log.w display warnings.

 Log.i display information messages/ expected log messages.

 Log.d display debug messages.

 Log.v display all log messages. (least used as it records more info than usual logging)
Android Logging Example
 In this example, we have used various log methods and you will see how it helps in debugging the
application.
 Open a New / Existing Android application
 Create a New Project if you have not created one before.
Write Log messages
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends Activity {

Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
b1=(Button)findViewById([Link]);

[Link](new [Link]() {
@Override
try {
// }
catch (Exception e)
{
Log.e(TAG, "Received an exception " + [Link]() );
}
public void onClick(View v) {
[Link]([Link],"You just Toasted me!!!",Toast.LENGTH_LONG).show();

Log.v(TAG, "Received an exception " );

/*Another way to display a Toast message


Toast t=[Link]([Link],"You just Toasted me!!!",Toast.LENGTH_LONG);
[Link]();
*/
} }); }
}

Add a Button

Now add a <Button> to the layout, immediately following the <EditText> element:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send" />
The height and width are set to "wrap_content" so the button is only as big as necessary to fit the button's text. This button doesn't need the android:id attribute, because it won't be referenced from
the activity code.
Run the application:
Build and run your app on a device or an emulator. You should be able to see all the log messages of
your application in the Logcat console.
If you don’t, then go to View > Tool Windows > Logcat or click on Logcat in the tool window bar. By
default Logcat shows all the messages of your application.
The Logcat toolbar provides the following buttons:

1. Clear logcat : Click to clear the visible log.

2. Scroll to the end : Click to jump to the bottom of the log and see the latest log messages. If you then click a line in the log, the view pauses

scrolling at that point.

3. Up the stack trace and Down the stack trace : Click to navigate up and down the stack traces in the log, selecting the subsequent filenames

(and viewing the correspnding line numbers in the editor) that appear in the printed exceptions. This is the same behavior as when you click on a

filename in the log.

4. Use soft wraps : Click to enable line wrapping and prevent horizontal scrolling (though any unbreakable strings will still require horizontal

scrolling).
5. Print : Click to print the logcat messages. After selecting your print preferences in the dialog that appears, you can also

choose to save to a PDF.

6. Restart : Click to clear the log and restart logcat. Unlike the Clear logcat button, this recovers and displays previous log

messages, so is most useful if Logcat becomes unresponsive and you don't want to lose your log messages.

7. Logcat header : Click to open the Configure Logcat Header dialog, where you can customize the appearance of each logcat

message, such as whether to show the date and time.

8. Screen capture : Click to capture a screenshot.

9. Screen record : Click to record a video of the device (for a maximum of 3 minutes).

You might also like