Upload
senthil-kanth
View
103
Download
3
Tags:
Embed Size (px)
DESCRIPTION
Introduction to Mobile Application Development This ppt contains the topic like,, WAP Network Structure, The WAP Gateway plays an important role, WAP Programming Model, WML Example, Java Platform, Java 2 Platform, Virtual Machines and horizontal and vertical APIs specified in configurations and Profiles, Configurations
Citation preview
1
Introduction to Mobile Application Development
2
Mobile Applications
Mobile Apps are apps or services that can be pushed to a mobile device or downloaded and installed locally.
Classification• Browser-based: apps/services developed in a
markup language• Native: compiled applications (device has a
runtime environment). Interactive apps such as downloadable games.
• Hybrid: the best of both worlds (a browser is needed for discovery)
3
Mobile PlatformsA wide variety of devices supporting different
platforms BlackBerry Palm OS Windows Mobile Symbian
Runtime environments & apps Browser-based apps (WAP) Flash-lite Java ME Qualcomm’s BREW Google’s Android
Having a choice is good…but not always… Device fragmentation
4
Web Content for Mobile Devices
Markup languages to deliver Web content to device browsers: HDML
Phone.com (now Openwave)
Compact HTML (cHTML)NTT DoCoMo’s i-mode network
WAP Forum’s WMLA standard for content delivered to mobile
devicesNow: openmobilealliance.org
5
WAP Network Structure
The WAP Gateway plays an important role
6
WAP Programming Model
Similar to the Web programming model with extensions for the wireless environment
7
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>
8
Java Platform
9
Java 2 Platform
Virtual Machines and horizontal and vertical APIs specified in configurations and Profiles
10
Configurations
A configuration defines the minimum APIs and VM capabilities for a family of devices: Similar requirements of memory size and
processing capabilitiesThe minimum APIs that an application
developer can expect to be available on implementing devices
May not contain any optional features
11
Profiles
A profile is a collection of APIs that supplement a configuration to provide capabilities for a specific vertical market
Qusay H. Mahmoud 12
How do they fit together?
Profiles are built on top of configurations
Qusay H. Mahmoud 13
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 14
MIDP
Targets mobile two-way communication devices implementing the CLDC
Built on top of CLDC to add other functionality like GUI, network implementation, local storage
It addresses: Display toolkit (user input) Persistent data storage HTTP based networking using CLDC generic connection
framework MIDP 1.0 released in December 2000, and MIDP 2.0
in November 2002 MIDP 2.0 new features: support for secure
networking (https), Game API, security mechanisms (code signing)
Qusay H. Mahmoud 15
KVM
Stands for Kilo Virtual MachineOriginated from a research project
called Spotless at Sun Research LabsImplements the classes defined in the
CLDC specificationNote: the UI classes are not part of the
CLDC
Qusay H. Mahmoud 16
KVM…
A complete runtime environment for small devices
Built from the ground up in CSmall footprint (40 – 80 KB)Class file verification takes place off-
deviceSupports multi-threadingSupports garbage collection
17
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 environmentApplications can call classes supported by the
device
18
Optional Packages
Core MIDP 2.0 functionality is limited. Vendors may include optional packages: JSR-75: File Connection and PIM APIs JSR-82: Bluetooth API JSR-120: Mobile Messaging API JSR-135: Mobile Media API JSR-179: Location API Many others…
19
JTWI
JSR-185: Java Technology for Wireless Industry (umbrella specification)
20
MSA
JSR-248: Mobile Service Architecture
21
Wireless Device Stack
Host OSHost OS
MIDPMIDP
MIDlet
Other Profiles
Other Profiles
Train Schedule
UIHTTP
No floats (CLDC 1.0)KVM
CLDC
22
CLDC Internals
The CLDC specification specifies VM features required by a CLDC implementation
Specifies requirements and APIs for Input/Output Networking
Qusay H. Mahmoud 23
Beyond the CLDC scope
Profiles implemented on top of CLDC specify APIs for: User Interface support Event handling Persistent support High-level application model
An example profile is the Mobile Information Device Profile (MIDP)
Qusay H. Mahmoud 24
Language & VM Compatibility
Goal: Full Java language and VM specification
compatibilityLanguage-level exception:
No floating point support in CLDC 1.0Manufacturers and developers can include their
own floating point
CLDC 1.1 supports floating point numbers
Qusay H. Mahmoud 25
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 26
CLDC APIs
Classes inherited from J2SE v1.3 are in packages: java.lang java.io java.util
New classes introduced by the CLDC are in package: javax.microedition javax.lang.ref (CLDC 1.1 only)
CLDC 1.1 (JSR 139) has superseded the original CLDC 1.0 spec (JSR 30).
Qusay H. Mahmoud 27
CLDC Libraries: java.lang.*
BooleanByteCharacterClassIntegerLongMathObjectRunnable
RuntimeShortStringStringBufferSystemThreadThrowable
Qusay H. Mahmoud 28
CLDC Libraries: java.io.*
ByteArrayInputStreamByteArrayOutputStrea
mDataInputDataOutputDataInputStreamDataOutputStreamInputStream
OutputStreamInputStreamReaderOutputStreamWrite
rPrintStreamReaderWriter
Qusay H. Mahmoud 29
CLDC Libraries: java.util.*
CalendarDateEnumerationHashtableRandomStackTimeZoneVector
No java.util.concurrent (use Threads)
Qusay H. Mahmoud 30
CLDC 1.0 vs. CLDC 1.1
Very similar. The most important differences are floating-point math capabilities and support for weak references. Classes Float and Double have been added A small subset of Java SE weak-reference
classes
31
MIDP internals
Goal: MIDP implementation must fit in small
footprint (128KB ROM) Must run with limited heap size (32-200KB
RAM)
To be implemented by device manufacturers, operators, or developers
32
MIDlets
A MIDlet consists of a class that extends the MIDlet class and other classes as needed
To handle events it must implement the CommandListener interface
public class MyMIDlet extends MIDlet implements CommandListener{
}
33
MIDP Application Lifecycle
MIDlets move from state to state in the lifecycle: Start: acquire resources and start executing Pause: release resources and wait Destroyed: release all resources and end all
activities Paused
Active
Destroyed
startApp()
destroyApp()
destroyApp()
pauseApp()
34
Example MIDlet
import javax.microedition.midlet.MIDlet;import javax.microedition.lcdui.*;
public class FirstMIDlet extends MIDlet { Display display = null; TextBox tb = null; public FirstMIDlet() { display = Display.getDisplay(this); }
35
Example MIDlet …
public void startApp() { tb = new TextBox("FirstMIDlet", "Welcome to MIDP Programming", 40, 0); display.setCurrent(tb); }
public void pauseApp() { }
public void destroyApp(boolean unconditional) { } }}
36
MIDlet Packaging
Two or mode MIDlets form a MIDlet suiteOne or more MIDlets may be packaged
in a single JAR file that includes: A manifest describing the contents Java classes for the MIDlet(s) Resource file(s) used by the MIDlet(s)
Each jar file is accompanied by a Java Application Descriptor (JAD) file
Qusay H. Mahmoud 37
MIDlet Packaging
Java Application Descriptor (JAD) file provides info:
Configuration properties Pre-download properties
Size, version, storage requirements
Qusay H. Mahmoud 38
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 39
Example MIDlet: Testing
emulator –Xdescriptor first.jad
Qusay H. Mahmoud 40
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>
Push registry: incoming network connections can launch specific MIDlets
Qusay H. Mahmoud 41
Simplifying the Development Effort
Sun Java Wireless Toolkit for CLDC
42
RIM’s BlackBerry
A smart phoneSelling feature has been instance, secure,
mobile access to emailAttracting a wider range of mobile consumersWell-engineering (consistency across
handhelds)Friction-free path to market applications (no
excessive certification)
Supports Java MERIM’s Java Development Environment (JDE)
43
BlackBerry
BlackBerry file format (.cod)RIM’s JDE comes with tools to convert
existing Java ME apps (.jad & .jar) into .cod files
Example: Use rapc to convert .jad & .jar into .cod Use javaloader to load on BlackBerry
44
BlackBerry
To utilize BlackBerry-specific features, use BlackBerry APIs
Application lifecycle is different
45
BlackBerry
Rest of code…
46
MIDP APIs
MIDP specifies APIs for:
User Interface Networking (based on CLDC) Persistent Storage Others…(Game API, security, etc)
47
MIDP Packages
MIDP 1.0 java.lang Java.util Java.io Javax.microedition.io Javax.microedition.lcdui Javax.microedition.midlet Javax.microedition.rms
48
MIDP Packages
MIDP 2.0 Javax.microedition.lcdui.game Javax.microedition.media Javax.microedition.media.control Javax.microedition.pki
49
MIDP User Interface
Not a subset of AWT or Swing because: AWT is designed for desktop computers Assumes certain user interaction models
(pointing device such as a mouse) Window management (resizing overlapping
windows). This is impractical for cell phones
Consists of high-level and low-level APIs
50
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
51
MIDP UI Programming Model
The central abstraction is a screenOnly one screen may be visible at a timeThree types of screens:
Predefined screens with complex UI components (List, TextBox)
Generic screens (Form where you can add text, images, etc)
Screens used with low-level API (Canvas)
52
MIDP UI and Display
The Display class is the display manager
It is instantiated for each active MIDletProvides methods to retrieve information
about the device’s display capabilitiesA screen is made visible by calling: Display’s setCurrent(screen);
53
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
54
MIDP UI Class Diagram
Major classes and interfaces:
55
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);
56
High-Level API Examples…
Form (Date/Time info):
DateField date = new DateField(“Today’s
date”, DateField.TIME);
Form form = new Form(“Date Info”);
form.append(date);
display.setCurrent(form);
57
High-Level Examples…
Form (Sign in screen):Display display = Display.getDisplay(this);TextField userName = new TextField(“LoginID:”, “”, 10,
TextField.ANY);TextField password = new TextField(“Password:”, “”,
10, TextField.PASSWORD);Form form = new Form(“Sign in”);form.append(userName);form.append(password);display.setCurrent(form);
58
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);
}
}
59
Low-level Example…
Instantiate and display MyCanvaspublic 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()}
60
Input Handling
High-Level API input is handled using abstract commands No direct access to soft buttons Commands are mapped to appropriate soft
buttons or menu items
61
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);
62
Event Handling: High-level
High-level Events:
Based on a listener model Screen objects can have listeners for
commands For an object to be a listener, it must
implement the CommandListener interface This interface has one method: commandAction
63
Event Handling: Example
MIDlet implements CommandListenerpublic 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(); } }}
64
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; }
65
Event Handling: Low-level
Low-level Events:
Low-level API gives developers access to key press events
Key events are reported with respect to key codes
MIDP defines key codes: KEY_NUM0 .. KEY_NUM9, KEY_STAR, KEY_POUND
66
Handling Events: example
Low-level eventsprotected void keyPressed(int keyCode) { if (keyCode > 0) { System.out.println("keyPressed " +((char)keyCode)); } else { System.out.println("keyPressed action “
+getGameAction(keyCode)); } }
67
MIDP UI Design Principles
Make the UI simple and easy to useUse the high-level API (portability)If you need to use low-level API, keep to
the platform-independent partMIDlets should not depend on any
specific screen sizeEntering data is tedious, so provide a
list of choices to select from
68
Networking
J2SE and J2EE networking APIs are not suitable for handheld devices Require several megabytes of memory to run Device manufacturers who work with circuit-
switched networks require TCP support Device manufacturers who work with packet-
switched networks require UDP support Other devices have specific mechanisms for
communications
69
CLDC Generic Connections
A set of related abstractions at the programming level
No abstractions for different forms of communications
All connections are created using the Connector.open()
If successful, it returns an object that implements one of the generic connection interfaces
70
Connection Interfaces
MIDP 1.0
71
MIDP 2.0
72
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”);
73
Advantages of CLDC Generic Connections
Isolate the differences between the setup of one protocol and another
Most of the application code remains the same regardless of the protocol you use
Note: CLDC itself does not provide any protocol implementation
74
MIDP Connectivity
It provides support for HTTP (HttpConnection)
Why? HTTP can be implemented using IP protocols or non-IP protocols
75
HttpConnection
Part of the javax.microedition.ioDefines the necessary methods and
constants for an HTTP connection
HttpConnection c = (HttpConnection) Connector.open(“http://quotes.yahoo.com”);
C.setRequestMethod(HttpConnection.POST);C.setRequestProperty(“Content-Language”, “en-CA”);
76
Invoking Remote Applications
A MIDlet may invoke remote applications:
Fetching a page Invoking a CGI script (GET or POST
method) Invoking a Servlet
77
Example: Invoke a CGI Script
GET Method:
String url = “http://host/cgi-bin/getgrade?idnum=182061”;c = (HttpConnection) Connector.open(url);c.setRequestMethod(HttpConnection.GET);// set some request properties: c.setRequestPropert(“ “, “
“);is = c.openDataInputStream();while((ch = is.read()) != -1) { b.append((char)ch);}
78
Example…
If you want to send data to a remote application:
String s = “stuffToSend”;byte postmsg[] = s.getBytes();for(int i=0;i<postmsg.length;i++) { os.writeBytes(postmsg[i]);}// ORos.write(s.getBytes());
79
Databases
A persistent storage: a place to store the state of objects
Facilities provided in J2SE and J2EE are not suitable for handheld devices
MIDP provides a record-oriented database mechanism to persistently store data and retrieve it later
80
MIDP’s RMS
Lightweight record-oriented database
Device independent API Unique recordID for each record within the
store A record is an array of bytes Shared within MIDlet suite Support for enumeration, sorting, and filtering
javax.microedition.rms
81
MIDP RMS Methods
Record StoreopenRecordStore, closeRecordStore, listRecordStore, deleteRecordStore, getRecordSize, getNumRecords
Record DataaddRecord, deleteRecord, getRecord, setRecord, getRecordSize
Record SelectionRecordEnumeration, RecordFilter, RecordComparator
82
RMS: Record Stores
To open a record store: RecordStore db =
RecordStore.openRecordStore(“myDB”, true);
To close a record store: db.closeRecordStore();
83
Create/Add a new record
To create a new record:
ByteArrayOutputStream baos = new ByteArrayOutputStream()
DataOutputStream dos = new DataOutputStream(baos);
dos.writeUTF(record);Byte b[] = baos.toByteArray();db.addRecord(b, 0, b.length);
84
Building a Stock Database
See appendix for source code: Stock.java StockDB.java QuotesMIDlet.java
85
StockQuotes MIDlet
86
Protection DomainsMIDP provides a security model to prevent
bad MIDlets from misbehavingModel: 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
87
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
deviceMIDlet suites can be signed or unsigned
(different protection domains)
88
Protection DomainsWhat 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…
89
BlackBerry…
That is why the BLackBerry rules! If your application uses Controlled APIs
(e.g. email), your must sign your application using keys from RIM
Register for keysCost: $100Request through online formTakes a couple of daysCan be used for 1,000,000 signatures
http://www.blackberry.com/SignedKeys
90
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 academicshttp://www.uoguelph.ca/~qmahmoud/javame & http://cmer.cis.uoguelph.ca
91
Thank you