Android Development Course
Ahmad Hanis
What Is Android
Android
is the operating system that controls
phones, tablets and many other devices. An
operating system is the core of the device
and helps applications communicate with
various hardware components. It also
provides a uniform user-interface to allow you
to interact with the device and applications
that run on the device.
2
Where it came from
Android was the development of Android Inc., started in
2003 in Palo Alto, California.
In 2005 Google, acquired Android, Inc. and the
development team behind Android.
The core of Android is based on Linux
The Android OS was officially announced at the end of
2007 and in 2008 Google made Android available under
an open source code license.
This means manufacturers and carriers can use and
modify Android without a licensing payment, making a
lower cost and more flexible solution for many companies.
3
Why Mobile App Development?
The fact that we can! Only a few years ago you had to
be in the Motorola inner circle to do it!
Mobile platform is the platform of the future
Job market is hot
Double-digit growth in world-wide smartphone ownership 3
Market for mobile software surges from $4.1 billion in 2009 to
$17.5 billion by 2012
2012 Dice.com more than 68130 open job available every day.
Dice.com: mobile app developers made $92,000 in 2012and
salaries expected to rise
Students (and faculty!) are naturally interested!
4
Why Android?
A lot of people have
them
70% of worldwide
market share
Students already know
Java and Eclipse
Low learning curve
BIT students can use
App Inventor for Android
1http://testkitchen.colorado.edu/projects/reports/smartphone/smartphone-appendix1/
http://www.gartner.com/it/page.jsp?id=1543014
Android
Operating
System
6
Android Devices
Phone
Tablet
E-Readers
Others
Android-Powered Microwave
By Touch Revolution at CES 2010
http://www.pocket-lint.com/news/30712/android-powered-microwavecooking-google
Brief History
1996
The WWW already had websites with color and
images
But, the best phones displayed a couple of lines
of monochrome text!
Enter:
Wireless Application Protocol (WAP) stripped down
HTTP for bandwidth reduction
Wireless Markup Language (WML) stripped down
HTML for content
9
Brief History
Many
Few developers to produce content (it wasnt fun!)
Really hard to type in URLs using the small
keyboards
Data fees frightfully expensive
No billing mechanism content difficult to monetize
Other
issues (WAP = Wait And Pay)
platforms emerged
Palm OS, Blackberry OS, J2ME, Symbian (Nokia),
BREW, OS X iPhone, Windows Mobile
10
Brief History - Android
2005
2007
Google acquires startup Android Inc. to start Android platform
Work on Dalvik VM begins
Open Handset Alliance announced
Early look at SDK
2008
Google sponsors 1st Android Developer Challenge
T-Mobile G1 announced
SDK 1.0 released
Android released open source (Apache License)
Android Dev Phone 1 released
11
Brief History cont.
2009
SDK 1.5 (Cupcake)
SDK 1.6 (Donut)
Support Wide VGA
SDK 2.0/2.0.1/2.1 (Eclair)
New soft keyboard with autocomplete feature
Revamped UI, browser
2010
Nexus One released to the public
SDK 2.2 (Froyo)
Flash support, tethering
SDK 2.3 (Gingerbread)
UI update, system-wide copy-paste
12
The Android Developer
Website
http://developer.android.com/index.html
This
should be your homepage for the next
semester!
13
Distribution of Devices
14
What is Google Android?
A software stack for mobile devices that includes
An operating system
Middleware
Key Applications
Uses Linux to provide core system services
Security
Memory management
Process management
Power management
Hardware drivers
15
Android Architecture
16
More details at: http://developer.android.com/guide/basics/what-is-android.html
Mobile Devices: Advantages (as
compared to fixed devices)
Always
with the user
Typically have Internet access
Typically GPS enabled
Typically have accelerometer & compass
Most have cameras & microphones
Many apps are free or low-cost
17
Mobile Devices: Disadvantages
Limited screen size
Limited battery life
Limited processor speed
Limited and sometimes slow network access
Limited or awkward input: soft keyboard, phone
keypad, touch screen, or stylus
Limited web browser functionality
Range of platforms & configurations across
devices
18
Mobile Applications
What
are they?
Any application that runs on a mobile device
Types
Web apps: run in a web browser
HTML, JavaScript, Flash, server-side components,
etc.
Native: compiled binaries for the device
Often make use of web services
19
Android Apps
Built
using Java and new SDK libraries
No support for some Java libraries like Swing &
AWT
Oracle currently suing Google over use
Java
code compiled into Dalvik byte code
(.dex)
Optimized for mobile devices (better memory
management, battery utilization, etc.)
Dalvik
VM runs .dex files
20
Building and running
Compiled resources
(xml files)
Android Debug Bridge
ADB is a client server program that connects clients on developer
machine to devices/emulators to facilitate development.
An IDE like Eclipse handles this entire process for you.
http://developer.android.com/guide/developing/building/index.html#detailed-build
21
Applications Are Boxed
By default, each app is run in its own Linux
process
Process started when apps code needs to be
executed
Threads can be started to handle time-consuming
operations
Each process has its own Dalvik VM
By default, each app is assigned unique Linux ID
Permissions are set so apps files are only visible to
that app
22
Android Architecture
23
Publishing and Monetizing
Paid apps in Android Market, various other
markets
Free, ad-supported apps in Android Market
Ad networks (Google AdMob, Quattro Wireless)
Sell your own ads
Services to other developers
Ex. Skyhook Wireless
(http://www.skyhookwireless.com/)
Contests (Android Developer Challenge)
Selling products from within your app
24
Android Market
http://www.android.com/market/
Has
various categories, allows ratings
Have both free/paid apps
Featured apps on web and on phone
The Android Market (and iTunes/App Store) is
great for developers
Level playing field, allowing third-party apps
Revenue sharing
25
Publishing to Android Market
Requires
$25 fee
Link
Google Developer Account
to a Merchant Account
Google Checkout
Link to your checking account
Google takes 30% of app purchase price
26
27
Android Design Philosophy
Applications
Fast
Apps must respond to user actions within 3 seconds
Secure
Resource constraints: <200MB RAM, slow processor
Responsive
should be:
Apps declare permissions in manifest
Seamless
Usability is key, persist data, suspend services
Android kills processes in background as needed
28
Other design principles
http://developer.android.com/design/index.ht
ml
Great
reference!
29
Apple vs. Google
Open
Handset Alliance
30+ technology companies
Commitment to openness, shared vision, and
concrete plans
Compare
with Mac/PC battles
Similar (many PC manufacturers, one Apple)
Different (Microsoft sells Windows, Google gives
away Android)
30
Android Development
31
Android Development
Android
Development Life Cycle
Setting up Eclipse + SDK + JDK + ADB
HelloWorld Your First Program
Hello World Demystify
GUI Layout & Java Codes
Button Action
Math Operation
Layout Selection
32
Development
process for an
Android app
33
http://developer.android.com/guide/developing/index.html
(1-a) Setup Dev Environment!!
Long
way
Install JDK and set path
Install Eclipse
Install Android SDK
Download Android API through SDK Manager
Configure Eclipse + Android SDK
Install Android Device Driver (Optional)
34
Setup Dev Environment!!
Shorter
way
Install JDK - Available from C:\AndroidSDKbundleEclipse-4win-x86\Tools\jdk-7u3-windowsi586)
Copy AndroidSDK-bundleEclipse-4win-x86
folder to your C:\ directory
Run Eclipse for the first time to
check the SDK integration
Set your workspace
you should get
35
Setup Dev Environment!!
If not then
proceed with SDK
configuration.
Go to Window
Preferences and
set the SDK
location
You should get
36
Setup Dev Environment!!
Finally to verify your
configuration check your
android SDK manager
from window menu.
Your SDK API already
preinstalled with API 17
and 10
You can download any
API youre interested
using the SDK manager.
37
Setup Dev Environment!!
Java Path If you use
the bundled android
development package,
the java build path has
been predefined in the
eclipse preferences.
To check if the java path
has been define properly
go to menu Window
Select Preferences.
38
(1-b)Setup AVD & Device for
Testing
Your
compiled android application can run
on:
AVD Android Virtual Device
Virtual device that simulate android operating system
Driver - Physical Android Device
Directly compiled to the device
39
(1-b) Setup AVD & Device for
Testing
AVD Android Virtual
Device Setup
Window Android
Virtual Device Manager
New Enter AVD name
Target API OK
Select AVD and click
start
40
(1-b) Setup AVD & Device for
Testing
Tips
on AVD
Make sure to select the
right API level for your
application.
Choose the device
resolution as low as
possible to improve
simulator performance.
Leave the AVD open
through out the application
development process.
41
(2) Development Hello World
(2-a) Hello World Your first android application!!!
zero programming required
Step 1
Step 2
42
(2) Development - Hello World
Step 3
Step 4
43
(2) Development Hello World
Step 5
Step 6
44
(2) Development Hello World
45
(2) Development Hello World
Step 1 Click run button
Running
Hello World
application on your AVD
Do not change anything to
the java codes and xml
interface!!!
To compile and run your
program on AVD:
Step 2 Run as Android Apps
46
(2) Development - Hello World
Step 3 Select AVD Profile
Step 4 Hello World Run
47
(2) Development- Demystify
Android
Development
Explained
Two main
programming
component
XML Interface
Layout
(Activity)
Java code for
activity
48
(2) Development - Demystify
Graphical Interface Layout
49
(2) Development - Demystify
Activity_main.xml
50
(2) Development - Demystify
Each object in the
layout has it own XML
code that describe its
properties.
Object properties can
be change by using
the properties window
51
(2) Development - Demystify
Automatically created for every new project
Link with activity
52
Exercise 1
Simple
Java Program that add a text to the
textview.
Create new android program and give a name
Android Text.
Add android:id=@id/textView1 in
activity_main.xml file or using you can use the
textview properties
53
(2-b) Development
Double
click on your MainActivity.java and
add the following code to the existing code:
Noticed the redline under TextView.
54
(2-b) Development
This error indicate
missing package.
To import missing
package place the
cursor on the error text
and click import
TextView
(android.widget)
Run the code on your
emulator
55
(2-b) Development
Textview
hard coded
with and show on the
screen.
56
Exercise 2
Add
two more textview and put your name
and matric number for each textview
respectively using the java codes.
57
Explanation
TextView = class (Need to import this class first before use)
teks = object you can use any legal programming name
setText = operation that can be performed.
58
Development Button Click
1.
2.
3.
Create new project
and give a name as
Button Handler
Change Form Layout
to Linear Layout.
Insert
TextView,editText1,bb
utton1 and
textView1(large) to the
form layout.
59
Development Button Click
4. Run the interface on your
AVD and you should get
5. To add Button operation
you need to create a
method that describe the
action of the button.
6. Access your
Activity_main.xml and look
for Button configuration
60
Development Button Click
7. Add the following line to
the button xml
configuration.
8. handleClick is basically
the name of the method
that will be use in
MainActivity.java
9. You can use any name as
long as it follows the
programming naming
convention.
61
Development Button Click
10. Open your
MainActivity.java
and add the
handleClick
method to the
class.
11. Follow exactly as
in this page.
Make sure
location of the
method is
correct!!!
62
Development Button Click
11.Run the code on
your AVD and insert
a text and press a
button
63
Explanation
Can you see the repetition and logic behind android
programming.
For every widget/component in the layout, it need to
have the reference in java code. Then object can
perform operation from selected method.
64
Development String
Manipulation
In
this exercise we are going to use our previous project (Button Click)
Modify the handleClick method as follow:
Run
the project
65
Development String
Manipulation
The result of string
manipulation where your
name is printed in reverse.
The use of build method
reverse for string
manipulation allow the input
string to reverse it content.
66
Development String
Manipulation advance
Further
modify your handleClick method with
the following codes
67
Development String Manipulation
advance Assignment!!!
The
codes given is
incomplete!!!.
Complete the code so that the
output from pressing the
button should display as in the
figure
68
Development Number
Manipulation
1. Start a new project and
name it Temperature
Converter
2. Change the form layout to
linear layout
3. Design the form layout as
in the figure
4. Run the form on your AVD
5. Add handleNom method
to your xml file. (where
and how??)
69
Development Number
Manipulation
6. Add the handleNom
method to your java
code. (where and
how??)
7. Run the program on
your AVD.
70
Exercise BMI Calculator
Develop a BMI calculator
using the following formula
and provide output based
on the scale.
71
Exercise BMI Calculator
You
should get the
output like this
72
Exercise - Modify BMI
To
add image for each result
Hide
softkeyboard
Input2=one of the edittext object in your java
Modify
your EditText android:inputType properties
so that only numbered softkeyboard will appear
73
Finally You Should Get
Final
Version
74
Date Picker
Create a new project name
Date Handler
Design your form as
Create a handleDate method in
your java file
Add handleDate onclick to your
activity form.xml.
75
Exercise Date formatter
Modify your layout as this
Modify your dateHandler method with the
following codes.
76
Exercise Date formatter
77
Input Control
Check Box
Create new project called Input
Control
Add two check box in the form
Create onCheckboxClicked method
in the java code
78
Input Control
Radio Button
Add two radio button to the form.
Group both radio button in the xml layout.
Add the following methods codes to java
79
Input Control
Toggle Button
Modify your current project
by adding toggle button to
your xml layout
Add the onToggleClicked
method to java class
80
Input Control
Spinner (dropdown
combo)
Add spinner to your current
project
To populate spinner with
data go to package
explorer and access the
value directory
strings.xml
Add new string array
81
Input Control
Go back to your
interface xml layout
and select spinner.
Go to spinner
properties
Select Entries and
choose
planet_array from
Reference Chooser
Run the code
82
Input Control
Responding from user select item from spinner
83
Input control
Modify
codes in the
main class
84
Input Control
Seekbar
Add Seekbar to the layout
Add the following to string.xml
Add following xml to seekbar layout
85
Input Control
Add
the following java codes
86
Create Menu
To create new menu access the
activity_main.xml under the res/menu
folder
Access the xml code and add new menu
by adding item tag under menu tag.
87
Create Menu
Menu
operation can be perform
by adding the following method
88
Alert Dialog
Add
a button and set the onClick properties
to clickAlert method as below
89
Intent
1.
2.
Create and navigate
between two or more
layout.
You need two java codes
and two layout xml.
Create a new project called
Hello Intent.
Copy and paste java and
xml into their directory and
rename to
SecondActivity.java and
second_activity.xml
90
Intent
Design both layouts
Open
AndroidManifest.xml
and add the
following codes to
the xml
SecondActivity
refering to
SecondActivity.java
91
Intent
Add onClick method for both buttons (OpenIntent2 for
MainActivity.java) and (OpenIntent1 for
SecondActivity.java)
Add the following method to MainActivity.java
Add the following method to SecondActivity.java
Make sure both java file contain onCreate method that calling the
correct xml layout file.
92
Passing Data between layout
Modify your Hello Intent project and by inserting in your
OpenIntent2 method in MainActivity.java
Add two textview in the
second_activity.xml layout.
93
Passing Data Between Layout
Add the following code in onCreate method in
SecondActivity.java
94
Call Build in Application
Browser
Create a new project
Add a EditView and a button to the layout
Add onClick method
Create a CallBrowser method in
MainActivity.java
Add the following code to AndroidManifest.xml
95
Call
Add one button to the existing project
Insert onClick option to the button
Add the following callPhone method to MainActivity.java
Insert the following permission into AndroidManifest.xml
96
Call
To enable call direct add the following
method to a new button (dont forget
to add onClick listener in xml layout.
97
GPS
Calling
Google Maps
98
SMS
Sending sms method
Using the same project add a new
button.
Add the onClick listener to the button
Add the following method
99
Read & Write Data
Read
and Write data to a text file
Method to store data to a textfile
100
Read & Write Data
Method to retrieve data
Dont forget to import required method and also
set the onClick listener
101
A math game
Create a new project and design your
layout as
Define the following var
Add the following code to onCreate
method
102
A math game
Add
the following handleCheck method
103
A math game
Add
the following handleNext method
104
A math game
Tips
Try to use the
properties for each
object to modify the
design.
Nested layout for
button
Import all required
class
105
Video and Audio
Play
audio
Add new folder inside your resource folder
(R.raw) . Then add any audio file to the folder by
dragging. (oppa is the name for this example)
106
Video and Audio
Play
Video
107
Notification
Create a new project and add a button and onClick
listener
108
Simple Animation
http://mycodeandlife.wordpress.com/2012/07/
07/android-simple-animation/
109
Publishing Android
App
Publishing Android App
Publishing Android App
Publishing Android App
General Publication Steps
1.
2.
3.
4.
Export your application as an APK (Android
Package) file.
Generate your own self-signed certificate
and digitally sign your application with it.
Deploy the signed application.
Use the Android Market for hosting and
selling your application.
Versioning
Beginning
with version 1.0 of the Android SDK
the AndroidManifest.xml file includess:
1.
2.
3.
4.
5.
android:versionCode and
android:versionName
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.suki.BuiltIn"
android:versionCode="1"
android:versionName="1.0" >
Other AndroidManifest element
android:icon
(within the <application>
element)
android:label (within the <application>
element)
<application
android:icon=@drawable/icon
android:label=myFirst App>
Digital Signing
All Android applications must be digitally signed
before they are allowed to be deployed
You need not purchase digital certificates from a
certificate authority (CA)
You can generate your own self-signed certificate &
use it to sign your Android applications.
Eclipse uses a default debug keystore to sign your
application.
A keystore is commonly known as a digital certificate.
Specific
Steps
1. Select your project
2.
3.
in Eclipse and then
select File
Export.
In the Export dialog,
expand the Android
item and select
Export Android
Application.
Click Next.
Specific
Steps
4. Select your project
& Click Next.
Specific Steps
5.
6.
7.
8.
Select the Create new keystore option to create
a new certificate (keystore) for signing your
application.
Enter a path to save your new keystore.
Enter a password to protect the keystore. (For this
example, type in password as the password).
Click Next.
9.
Specific
Steps
Provide an alias for
10.
11.
the private key.
Enter a password to
protect the private
key. (enter
password)
Enter a validity period
for the key. Enter 50.
12.
According to Google, your
application must be signed
with a cryptographic private
key whose validity period
ends after 22 October 2033.
Click Next.
Specific
Steps
13. Enter a path to store the destination
14.
APK file.
Click Finish.
APK file will now be generated.
Deploying APK Files
Deploying
manually using the adb.exe tool
Hosting the application on a web server
Publishing through the Android Market
Besides the above methods, you can install
your applications on users devices through emails, SD card, etc. As long as you can transfer
the APK file onto the users device, you can
install the application.
Publishing on the Google Play
1.
Create a developer profile at
http://market.android.com/publish/Home.
2.
For this, you need a Google account (such as your
Gmail account).
Once you have logged in to the Android Market, you
first create your developer profile.
Click Continue (after entering the required
information).
Publishing on the Google Play
3.
4.
5.
Publishing
on
For publishing on
thethe Google Play
Android Market, you
need to pay a onetime registration fee,
currently U.S.$25.
Click the Google
Checkout button to
be redirected to a
page where you can
pay the registration
fee.
After paying, click the
Continue link.
Publishing on the Google Play
Uploading
Your
You
will be asked
to
supply some details
for your application:
The application
in APK format
At least two
screenshots.
A high-resolution
application icon.
This size of this
image must be
512512 pixels.
APK Files