Introduction To Mobile Application Development
Introduction To Mobile Application Development
Application Development
Qusay H. Mahmoud 4
WAP Network Structure
Qusay H. Mahmoud 5
WAP Programming Model
Qusay H. Mahmoud 6
WML Example
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML
1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="MyFirstCard" title="First Card">
<p align="center">
My First WML Example
</p>
</card>
</wml>
Qusay H. Mahmoud 7
Java Platform
Qusay H. Mahmoud 8
Java 2 Platform
Qusay H. Mahmoud 9
Configurations
Qusay H. Mahmoud 10
Profiles
Qusay H. Mahmoud 11
How do they fit together?
Qusay H. Mahmoud 12
CLDC
Connected Limited Device Configuration
Defines APIs and JVM capabilities
APIs are subset of Java SE (java.lang, java.util, java.io)
Also defines connectivity framework (javax.microedition,
io) but implementation left for profiles
CLDC 1.0 released in May 2000 (no support for
floating point numbers). CLDC 1.1 in March 2003
Targets devices (such as cell phones) with:
160 (192) to 512 KB of total memory available for Java
technology
Limited power (e.g. battery)
Limited connectivity to a network (wireless)
Constrained User Interface (small screen)
Qusay H. Mahmoud 13
MIDP
Qusay H. Mahmoud 14
KVM
Qusay H. Mahmoud 15
KVM…
Qusay H. Mahmoud 16
KVM Security
VM level security
Off-device pre-verification
Small in-device verification
Application level security
No Security Manager
Sandbox security model:
Applications run in a closed environment
Applications can call classes supported by the device
Qusay H. Mahmoud 17
Optional Packages
Qusay H. Mahmoud 18
JTWI
Qusay H. Mahmoud 19
MSA
JSR-248: Mobile Service Architecture
Qusay H. Mahmoud 20
Wireless Device Stack
MIDle Train
t Schedule
Other
Other MIDP UI
Profiles MIDP HTTP
Profiles
CLDC
No floats
KVM (CLDC 1.0)
Host
HostOS
OS
Qusay H. Mahmoud 21
CLDC Internals
Qusay H. Mahmoud 22
Beyond the CLDC scope
Qusay H. Mahmoud 23
Language & VM
Compatibility
Goal:
Full Java language and VM specification
compatibility
Language-level exception:
No floating point support in CLDC 1.0
Manufacturers and developers can include their own
floating point
CLDC 1.1 supports floating point numbers
Qusay H. Mahmoud 24
CLDC vs. Java SE JVM
Limitations in CLDC supporting JVM:
No floating point support (yes in CLDC 1.1)
No finalization
Limited error handling
No Java Native Interface (JNI)
No support for reflection
No thread groups or daemon threads
No weak references (yes in CLDC 1.1)
No class loaders
Partial bytecode verifier
Qusay H. Mahmoud 25
CLDC APIs
Qusay H. Mahmoud 26
CLDC Libraries: java.lang.*
Boolean Runtime
Byte Short
Character String
Class StringBuffer
Integer System
Long Thread
Math Throwable
Object
Runnable
Qusay H. Mahmoud 27
CLDC Libraries: java.io.*
ByteArrayInputStream OutputStream
ByteArrayOutputStream InputStreamReader
DataInput OutputStreamWriter
DataOutput PrintStream
DataInputStream Reader
DataOutputStream Writer
InputStream
Qusay H. Mahmoud 28
CLDC Libraries: java.util.*
Calendar No java.util.concurrent
Date (use Threads)
Enumeration
Hashtable
Random
Stack
TimeZone
Vector
Qusay H. Mahmoud 29
CLDC 1.0 vs. CLDC 1.1
Qusay H. Mahmoud 30
MIDP internals
Goal:
MIDP implementation must fit in small footprint
(128KB ROM)
Must run with limited heap size (32-200KB RAM)
Qusay H. Mahmoud 31
MIDlets
Paused
pauseApp() startApp()
Active destroyApp()
destroyApp()
Destroyed
Qusay H. Mahmoud 33
Example MIDlet
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
Qusay H. Mahmoud 34
Example MIDlet …
Qusay H. Mahmoud 35
MIDlet Packaging
Qusay H. Mahmoud 36
MIDlet Packaging
Configuration properties
Pre-download properties
Size, version, storage requirements
Qusay H. Mahmoud 37
Example MIDlet…
Compile (javac)
Preverify (off device preverification)
Create a JAR file: first.jar
Create a JAD file: first.jad
MIDlet-Name: MyFirst
MIDlet-Version: 1.0.0
MIDlet-Vendor: Sun Microsystems, Inc.
MIDlet-Description: My First MIDlet
MIDlet-Info-URL: http://java.sun.com/j2me/
MIDlet-Jar-URL: first.jar
MIDlet-Jar-Size: 1063
MicroEdition-Profile: MIDP-1.0
MicroEdition-Configuration: CLDC-1.0
MIDlet-1: MyFirst,, FirstMIDlet
Qusay H. Mahmoud 38
Example MIDlet: Testing
Qusay H. Mahmoud 39
MIDlet Example: Deploy
Local: USB, Bluetooth
Web:
To deploy a MIDlet on a web server, you need to add a new MIME
type:
text/vnd.sun.j2me.app-descriptor jad
application/java-archive jar
Create an HTML file with link to the .jar file
Use the following command to run:
emulator –Xdescriptor:<JAD file>
Qusay H. Mahmoud 41
RIM’s BlackBerry
A smart phone
Selling feature has been instance, secure, mobile
access to email
Attracting a wider range of mobile consumers
Well-engineering (consistency across handhelds)
Friction-free path to market applications (no
excessive certification)
Supports Java ME
RIM’s Java Development Environment (JDE)
Qusay H. Mahmoud 42
BlackBerry
Qusay H. Mahmoud 43
BlackBerry
Qusay H. Mahmoud 44
BlackBerry
Rest of code…
Qusay H. Mahmoud 45
MIDP APIs
User Interface
Networking (based on CLDC)
Persistent Storage
Others…(Game API, security, etc)
Qusay H. Mahmoud 46
MIDP Packages
MIDP 1.0
java.lang
Java.util
Java.io
Javax.microedition.io
Javax.microedition.lcdui
Javax.microedition.midlet
Javax.microedition.rms
Qusay H. Mahmoud 47
MIDP Packages
MIDP 2.0
Javax.microedition.lcdui.game
Javax.microedition.media
Javax.microedition.media.control
Javax.microedition.pki
Qusay H. Mahmoud 48
MIDP User Interface
Qusay H. Mahmoud 49
MIDP UI APIs
High-level API
Applications should be runnable and usable in all
MIDP devices
No direct access to native device features
Low-level API
Provides access to native drawing primitives,
device key events, native input devices
Allows developers to choose to compromise
portability for user experience
Qusay H. Mahmoud 50
MIDP UI Programming
Model
Qusay H. Mahmoud 51
MIDP UI and Display
Qusay H. Mahmoud 52
MIDP UI Classes
javax.microedition.lcdui classes:
Alert, AlertType, Canvas, ChoiceGroup,
Command, DateField, Display, Displayable, Font,
Form, Gauge, Graphics, Image, ImageItem,
Item, List, Screen, StringItem, TextBox,
TextField, Ticker
javax.microedition.lcdui interfaces:
Choice, CommandListener, ItemStateListener
Qusay H. Mahmoud 53
MIDP UI Class Diagram
Qusay H. Mahmoud 54
High-Level API Examples
List:
Display display = Display.getDisplay(this);
List menu = new List(“Method of payment”, Choice.EXCLUSIVE);
menu.append(“Visa”);
menu.append(“MasterCard”);
menu.append(“Amex”);
display.setCurrent(menu);
Qusay H. Mahmoud 55
High-Level API Examples…
Qusay H. Mahmoud 56
High-Level Examples…
Qusay H. Mahmoud 57
Low-level Example
Canvas:
public class MyCanvas extends Canvas {
public void paint(Graphics g) {
g.setColor(255, 0, 0);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(255, 255, 255);
g.drawString("Hello World!", 0, 0, g.TOP | g.LEFT);
}
}
Qusay H. Mahmoud 58
Low-level Example…
Instantiate and display MyCanvas
public class MyMidlet extends MIDlet {
public MyMidlet() { // constructor
}
public void startApp() {
Canvas canvas = new MyCanvas();
Display display = Display.getDisplay(this);
display.setCurrent(canvas);
}
// pauseApp() and destroyApp()
}
Qusay H. Mahmoud 59
Input Handling
Qusay H. Mahmoud 60
Input Handling: Example
TextBox screen with commands:
Display display = Display.getDisplay(this);
TextBox tb = new TextBox(“MIDP”, “Welcome to MIDP
Programming”, 40, TextField.ANY);
Command exit = new Command(“Exit”, Command.SCREEN, 1);
Command info = new Command(“Info”, Command.SCREEN, 2);
Command buy = new Command(“Buy”, Command.SCREEN, 2);
tb.addCommand(exit);
tb.addComment(info);
tb.addCommand(buy);
display.setCurrent(tb);
Qusay H. Mahmoud 61
Event Handling: High-level
High-level Events:
Qusay H. Mahmoud 62
Event Handling: Example
MIDlet implements CommandListener
public class MyMIDlet extends MIDlet implements CommandListener
{
Command exitCommand = new Command(…);
// other stmts
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
Qusay H. Mahmoud 63
Event Handling: Example
Handling List events:
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) { ..
} else {
List down = (List)display.getCurrent();
switch(down.getSelectedIndex()) {
case 0: testTextBox();break;
case 1: testList();break;
case 2: testAlert();break;
case 3: testDate();break;
case 4: testForm();break;
}
Qusay H. Mahmoud 64
Event Handling: Low-level
Low-level Events:
Qusay H. Mahmoud 65
Handling Events: example
Low-level events
protected void keyPressed(int keyCode) {
if (keyCode > 0) {
System.out.println("keyPressed " +((char)keyCode));
} else {
System.out.println("keyPressed action “
+getGameAction(keyCode));
}
}
Qusay H. Mahmoud 66
MIDP UI Design Principles
Qusay H. Mahmoud 67
Networking
MIDP 1.0
Qusay H. Mahmoud 70
MIDP 2.0
Qusay H. Mahmoud 71
Example Connections
HTTP:
Connector.open(“http://www.host.com”);
Socket:
Connector.open(“socket://host.com:80”);
Datagram:
Connector.open(“datagram://address:port”);
File: Connector.open(“file:/myfile.txt”);
Qusay H. Mahmoud 72
Advantages of CLDC
Generic Connections
Qusay H. Mahmoud 73
MIDP Connectivity
Qusay H. Mahmoud 74
HttpConnection
HttpConnection c = (HttpConnection)
Connector.open(“http://quotes.yahoo.com”);
C.setRequestMethod(HttpConnection.POST);
C.setRequestProperty(“Content-Language”, “en-CA”);
Qusay H. Mahmoud 75
Invoking Remote
Applications
Fetching a page
Invoking a CGI script (GET or POST method)
Invoking a Servlet
Qusay H. Mahmoud 76
Example: Invoke a CGI
Script
GET Method:
Qusay H. Mahmoud 77
Example…
Qusay H. Mahmoud 78
Databases
Qusay H. Mahmoud 79
MIDP’s RMS
javax.microedition.rms
Qusay H. Mahmoud 80
MIDP RMS Methods
Record Store
openRecordStore, closeRecordStore,
listRecordStore, deleteRecordStore,
getRecordSize, getNumRecords
Record Data
addRecord, deleteRecord, getRecord, setRecord,
getRecordSize
Record Selection
RecordEnumeration, RecordFilter,
RecordComparator
Qusay H. Mahmoud 81
RMS: Record Stores
Qusay H. Mahmoud 82
Create/Add a new record
Qusay H. Mahmoud 84
StockQuotes MIDlet
Qusay H. Mahmoud 85
Protection Domains
MIDP provides a security model to prevent bad
MIDlets from misbehaving
Model: protection domains (determine what
operations are permitted in a MIDlet)
When a MIDlet suite is installed, it goes into some
protection domain (rules to determine what
happens when trying to perform a sensitive
operation)
Net connection (costs money)
Reading a file (privacy)
Operation: allowed, denied, user prompted for
permission
Qusay H. Mahmoud 86
Protection Domains
The specification is flexible and leaves
manufacturers and carriers room for
implementing security models
Implementations vary:
Capturing an image restricted on some devices
Playing audio or video restricted on some device
MIDlet suites can be signed or unsigned
(different protection domains)
Qusay H. Mahmoud 87
Protection Domains
What to expect?
Un-trusted domain where unsigned MIDlets are denied
permission or user promoted for every sensitive
operation
Manufacturer or carrier domain: allow MIDlets the most
freedom
Identified 3rd party domain: signed MIDlets with keys
obtained from known certification authorities (less
freedom because no testing or certification by authorized
parties)
Devices from different vendors behave differently…
Qusay H. Mahmoud 88
BlackBerry…
Qusay H. Mahmoud 89
Java ME Resources
Java ME:
http://java.sun.com/j2me
Sun Java Wireless Toolkit for CLDC:
http://java.sun.com/products/sjwtoolkit
RIM BlackBerry JDE:
http://na.blackberry.com/eng/developers/downloads/jde.jsp
NetBeans:
http://www.netbeans.org
JCP:
http://www.jcp.org
Resources for academics
http://www.uoguelph.ca/~qmahmoud/javame &
http://cmer.cis.uoguelph.ca
Qusay H. Mahmoud 90
Thank you
Q&A
Qusay H. Mahmoud 91