This document provides an overview of Android including:
- Android is an open source software platform and operating system for mobile devices based on the Linux kernel.
- It allows developers to write managed code using the Java programming language and includes features like views, content providers, notifications and more.
- The Android SDK provides tools for building, testing and debugging Android apps and uses a specific project structure.
- Input controls like buttons, text fields, checkboxes and spinners allow users to interact with apps. Attributes define behaviors of these controls.
- Screen size, density, resolution and orientation impact user interfaces and alternative resources support different densities.
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Everything You Need to Know About Android
1. What is Android?
• A software platformand operatingsystem for mobile
devices
• Based on the Linux kernel
• Developed by Google and later the Open Handset
Alliance (OHA)
• Allows writingmanaged code in the Java language
• Unveilingof the Android platform was announced on
5 November 2007 with the founding of OHA
November 5, 2007 (Android Birth Day)
• The Android SDK was firstissued as an “early look”
releasein November 2007.
• In September 2008 T-Mobile announced the
availability of the T-Mobile G1, the firstsmartphone
based on the Android Platform.
• In October 2008,Google made the source code of the
Android Platformavailableunder Apache’s open
sourcelicense.
•
Code name
Version
number
API level
(No codename)[2] 1.0 1
(Internally known
as "Petit Four")[2] 1.1 2
Cupcake 1.5 3
Donut[3] 1.6 4
Eclair[4] 2.0 – 2.1 5 – 7
Code name
Version
number
API level
Froyo[5] 2.2 – 2.2.3 8
Gingerbread[6] 2.3 – 2.3.7 9 – 10
Honeycomb[7] 3.0 – 3.2.6 11 – 13
Ice Cream
Sandwich[8]
4.0 – 4.0.4 14 – 15
Jelly Bean[9] 4.1 – 4.3.1 16 – 18
KitKat[10] 4.4 – 4.4.4 19 – 20
Lollipop[12] 5.0 – 5.1.1 21 – 22
Marshmallow[13] 6.0 – 6.0.1 23
Nougat[14] 7.0 – 7.1.2 24 – 25
Oreo[15] 8.0 – 8.1 26 – 27
•
• Most of the application framework accesses these
core libraries through the Dalvik VM, the gateway
to the Android Platform
•
•
•
•
2. • Android Application Framework
Feature Role
View
System
Used to build an application,includinglists,
grids,textboxes, buttons, and embedded
web browser
Content
Provider
Enablingapplications to access data fromother
applicationsor to sharetheir own data
Resourc
e
Manage
r
Providingaccess to non-code resources
(localized string,graphics,and layoutfiles)
Notifica
tion
Manage
r
Enablingall applicationsto display customer alerts
in the status bar
Activity
Manage
r
Managingthe lifecycleof applicationsand
providinga common navigation backstack
• The media libraries are based on PacketVideo’s
(http://www.packetvideo.com/) OpenCORE.
These libraries areresponsiblefor recording and
playback of audio and video formats. A library
called Surface Manager controls access to the
display systemand supports 2D and 3D.
• The WebKit library isresponsiblefor browser
support; it is the same library thatsupports
Google Chrome and Apple Inc.’s Safari.The
FreeType library isresponsiblefor font support.
• SQLite (http://www.sqlite.org/) is a relational
databasethat is availableon the device itself.
SQLite is also an independent open sourceeffort
for relational databases and notdirectly tied to
Android. You can acquireand use tools meant for
SQLite for Android databases as well.
• Dalvik Virtual Machine (DVM)
o Providingenvironment on which every Android
application runs
o Each Android application runs in its own process,
with its own instanceof the Dalvik VM.
o Dalvik has been written so that a device can run
multipleVMs efficiently.
o Register-based virtual machine
Resumed
In this state, the activity is in the foreground and the
user can interactwith it. (Also sometimes referred to as
the "running" state.)
Paused
In this state, the activity is partially obscured by
another activity—the other activity that's in the
foreground is semi-transparentor doesn't cover the entire
screen. The paused activity does not receive user input
and cannot execute any code.
Stopped
In this state, the activity is completely hidden and
not visibleto the user; it is considered to be in the
background.Whilestopped, the activity instanceand all its
state information such as member variables isretained,
but itcannot execute any code.
The other states (Created and Started) aretransientand
the system quickly moves from them to the next state by
callingthe next lifecyclecallback method. That is,after the
system calls onCreate(),itquickly calls onStart(),which is
quickly followed by onResume().
Defining Main Activity
You can define which activity to use as the main
activity in the Android manifestfile, AndroidManifest.xml,
which is atthe root of your projectdirectory.
The main activity for your app must be declared in
the manifest with an <intent-filter> that includes the
MAIN action and LAUNCHER category.
Module 2
Android SDK
The Android SDK provides you the API libraries and
developer tools necessary to build,test, and debug apps
for Android
3. Android Directory Structure
Managing Projects
Projects actas containers for storingthings such as
code and resourcefiles.The SDK tools expect your projects
to followa specific structureso itcan compileand package
your application correctly,so itis highly recommended
that you create them with Eclipseand ADT or with
theandroid tool on the command line.
3 types of project
1. Android Projects
2. Test Projects
3. Library Projects
Android Projects
An Android project is the container for your
application'ssourcecode,resource files,and files such as
the Ant build and Android Manifest file.An application
project is the main type of project and the contents are
eventually builtinto an .apk filethat you install on a
device.
Test Projects
These projects contain code to test your
application projects and arebuiltinto applications thatrun
on a device.
Library Projects
These projects contain shareableAndroid source
code and resources that you can reference in Android
projects.This is useful when you have common code that
you want to reuse. Library projects cannotbe installed
onto a device, however, they are pulled into the .apk fileat
build time.
Android Application Package (APK)
APK is the fileformat used to distributeand install
application softwareand middlewareonto Google’s
Android operatingsystem.
Module 3
Input Controls
are the interactivecomponents in your app's user
interface. Android provides a wide variety of controls you
can use in your UI, such as buttons, text fields,seek bars,
checkboxes, zoom buttons, toggle buttons, and many
more.
Button
A button consists of text or an icon (or both text and
an icon) that communicates what action occurs when the
user touches it.
Three ways to create a button in your layout
1. With text, usingthe Button class
2. With an icon,usingthe ImageButton
class
3. With text and an icon usingButton Class
with some additional attribute
4. Button Click Events
When the user clicks a button, the Button object
receives an on-click event.
To define the click event handler for a button, add
the android:onClick attribute to the <Button> element in
your XML layout.
Button Style
android:background
attribute for customizingindividual buttons with a
different background with drawable or color resource.
Text Fields
A text field allows theuser to type text into your app.
It can be either singlelineor multi-line.Touchinga text
field places the cursor and automatically displaysthe
keyboard. In addition to typing, text fields allowfor a
variety of other activities,such as textselection (cut, copy,
paste) and data look-up via auto-completion.
You can specify the type of keyboard you want for your
EditText object with the android:inputType attribute.
"text"
Normal text keyboard.
"textEmailAddress"
Normal text keyboard with the @ character.
"textUri"
Normal text keyboard with the / character.
"number"
Basic number keypad.
"phone"
Phone-style keypad.
"textCapSentences"
Normal text keyboard that capitalizes thefirstletter for
each new sentence.
"textCapWords"
Normal text keyboard that capitalizes every word. Good
for titles or person names.
"textAutoCorrect"
Normal text keyboard that corrects commonly
misspelled words.
"textPassword"
Normal text keyboard, but the characters entered
turn into dots.
"textMultiLine"
Normal text keyboard that allowusers to input longstrings
of text that includelinebreaks (carriagereturns).
Providing Auto-complete Suggestions
If you want to provide suggestions to users as they
type, you can use a subclass of EditText called
AutoCompleteTextView.
To implement auto-complete, you must specify an
(@link android.widget.Adapter) that provides the text
suggestions.
Checkboxes
Checkboxes allowthe user to select one or more
options from a set. Typically,you should present each
checkbox option in a vertical list.
To create each checkbox option,create
a CheckBox in your layout.Because a set of checkbox
options allows theuser to select multipleitems, each
checkbox is managed separately and you must register a
click listener for each one.
Radio Buttons
Radio buttons allowthe user to select one option
from a set. You should use radio buttons for optional sets
that are mutually exclusiveif you think that the user needs
to see all availableoptions side-by-side.If it's not
necessary to show all options side-by-side,usea
spinner instead.
Responding to Click Events
5. To define the click event handler for a checkbox and
radiobutton add the android:onClick attribute to
the <CheckBox> and <RadioButton> element in your XML
layout.Both checkbox and radiobutton follows the
definition of click event handler of a button
Toggle Buttons
A toggle button allows theuser to change a setting
between two states.
You can add a basic toggle button to your layoutwith
the ToggleButton object. Android 4.0 (API level 14)
introduces another kind of toggle button called a switch
that provides a slider control,which you can add with
a Switch object.
The ToggleButton and Switch controls aresubclasses
of CompoundButton and function in the same manner, so
you can implement their behavior the same way.
Spinners
Spinners providea quick way to select one value
from a set. In the default state, a spinner shows its
currently selected value.Touching the spinner displaysa
dropdown menu with all other availablevalues,from
which the user can select a new one.
The createFromResource() method allows you to
create an ArrayAdapter from the stringarray.The third
argument for this method is a layoutresource that defines
how the selected choiceappears in the spinner control.
The simple_spinner_item layoutis provided by the
platformand is the default layoutyou should useunless
you'd liketo define your own layoutfor the spinner's
appearance.
You should then
call setDropDownViewResource(int) to specify the layout
the adapter should useto display thelistof spinner
choices (simple_spinner_dropdown_item is another
standard layoutdefined by the platform).
Call setAdapter() to apply the adapter to
your Spinner.
Pickers
Android provides controls for the user to pick a time
or pick a date as ready-to-use dialogs.Each picker provides
controls for selectingeach partof the time (hour, minute,
AM/PM) or date (month, day, year). Usingthese pickers
helps ensure that your users can pick a time or date that is
valid,formatted correctly,and adjusted to the user's
locale.
DialogFragment
use to host time or date picker, manages the dialog
lifecyclefor you and allows you to display thepickers in
6. different layoutconfigurations,such asin a basicdialogon
handsets or as an embedded part of the layouton large
screens.
Creating a Time Picker
To display a TimePickerDialog using DialogFragment,
you need to define a fragment classthatextends
DialogFragment and return a TimePickerDialog from the
fragment's onCreateDialog() method.
Extending DialogFragment for a time picker
1. Define the onCreateDialog() method to
return an instanceof TimePickerDialog
2. Implement the
TimePickerDialog.OnTimeSetListener
interface to receive a callback when the
user sets the time.
•
Input Controls arethe interactivecomponents in
your app's user interface.
• A button consists of text or an icon (or both text
and an icon) that communicates what action
occurs when the user touches it.
• Three ways to create a button in your layout
• With text, usingthe Button class
• With an icon,usingthe ImageButton
class
• With text and an icon using Button Class
with some additional attribute
• android:onClick attributecan be use for
eventhandler for common controls
• The method signaturefor android:onClick attribute
must be public,void,and with a parameter View.
Module 4
Screen Size
Actual physical size,measured as the screen's
diagonal.
Screen Density
The quantity of pixels within a physical area of the
screen; usually referred to as dpi (dots per inch).
Orientation
The orientation of the screen from the user's pointof
view. This is either landscapeor portrait,meaningthat the
screen's aspectratio is either wide or tall,respectively.
Resolution
The total number of physical pixelson a screen.
When addingsupportfor multiplescreens, applicationsdo
not work directly with resolution;applications should be
concerned only with screen size and density, as specified
by the generalized sizeand density groups.
Density-independent pixel (dp)
A virtual pixel unitthatyou should usewhen defining
UI layout,to express layoutdimensions or position in a
density-independent way. Based on a 160 dpi screen.
SIZES AND DENSITIES
Android divides the range of actual screen sizes and
densities into:
General Sizes
small,normal,large,and xlarge
General Densities
ldpi (low),mdpi (medium), hdpi (high),and xhdpi
(extra high)
Alternative Drawables
To create alternativebitmap drawables for different
densities,you should followthe 3:4:6:8 scaling
ratio between the four generalized densities.
• 36x36 for low-density
• 48x48 for medium-density
• 72x72 for high-density
• 96x96 for extra high-density
7. Attributes
Every View and ViewGroup object supports their
own variety of XML attributes. Some attributes are specific
to a View object (for example, TextView supports
the textSize attribute), but these attributes are also
inherited by any View objects that may extend this class.
ID
Any View object may have an integer ID associated
with it, to uniquely identify the View within the tree. When
the application is compiled,this ID is referenced as an
integer, but the ID is typically assigned in the layoutXML
fileas a string,in the id attribute.
Layout Parameters
XML layoutattributes
named layout_something define layoutparameters for the
View that are appropriatefor the ViewGroup in which it
resides.
Every ViewGroup classimplements a nested class
that extends ViewGroup.LayoutParams. This subclass
contains property types that define the sizeand position
for each child view, as appropriatefor the view group.