introduction to mobile application development
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, ConfigurationsTRANSCRIPT
![Page 1: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/1.jpg)
1
Introduction to Mobile Application Development
![Page 2: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/2.jpg)
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)
![Page 3: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/3.jpg)
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
![Page 4: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/4.jpg)
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
![Page 5: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/5.jpg)
5
WAP Network Structure
The WAP Gateway plays an important role
![Page 6: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/6.jpg)
6
WAP Programming Model
Similar to the Web programming model with extensions for the wireless environment
![Page 7: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/7.jpg)
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>
![Page 8: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/8.jpg)
8
Java Platform
![Page 9: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/9.jpg)
9
Java 2 Platform
Virtual Machines and horizontal and vertical APIs specified in configurations and Profiles
![Page 10: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/10.jpg)
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
![Page 11: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/11.jpg)
11
Profiles
A profile is a collection of APIs that supplement a configuration to provide capabilities for a specific vertical market
![Page 12: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/12.jpg)
Qusay H. Mahmoud 12
How do they fit together?
Profiles are built on top of configurations
![Page 13: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/13.jpg)
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)
![Page 14: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/14.jpg)
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)
![Page 15: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/15.jpg)
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
![Page 16: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/16.jpg)
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
![Page 17: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/17.jpg)
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
![Page 18: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/18.jpg)
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…
![Page 19: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/19.jpg)
19
JTWI
JSR-185: Java Technology for Wireless Industry (umbrella specification)
![Page 20: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/20.jpg)
20
MSA
JSR-248: Mobile Service Architecture
![Page 21: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/21.jpg)
21
Wireless Device Stack
Host OSHost OS
MIDPMIDP
MIDlet
Other Profiles
Other Profiles
Train Schedule
UIHTTP
No floats (CLDC 1.0)KVM
CLDC
![Page 22: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/22.jpg)
22
CLDC Internals
The CLDC specification specifies VM features required by a CLDC implementation
Specifies requirements and APIs for Input/Output Networking
![Page 23: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/23.jpg)
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)
![Page 24: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/24.jpg)
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
![Page 25: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/25.jpg)
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
![Page 26: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/26.jpg)
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).
![Page 27: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/27.jpg)
Qusay H. Mahmoud 27
CLDC Libraries: java.lang.*
BooleanByteCharacterClassIntegerLongMathObjectRunnable
RuntimeShortStringStringBufferSystemThreadThrowable
![Page 28: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/28.jpg)
Qusay H. Mahmoud 28
CLDC Libraries: java.io.*
ByteArrayInputStreamByteArrayOutputStrea
mDataInputDataOutputDataInputStreamDataOutputStreamInputStream
OutputStreamInputStreamReaderOutputStreamWrite
rPrintStreamReaderWriter
![Page 29: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/29.jpg)
Qusay H. Mahmoud 29
CLDC Libraries: java.util.*
CalendarDateEnumerationHashtableRandomStackTimeZoneVector
No java.util.concurrent (use Threads)
![Page 30: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/30.jpg)
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
![Page 31: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/31.jpg)
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
![Page 32: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/32.jpg)
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{
}
![Page 33: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/33.jpg)
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()
![Page 34: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/34.jpg)
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); }
![Page 35: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/35.jpg)
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) { } }}
![Page 36: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/36.jpg)
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
![Page 37: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/37.jpg)
Qusay H. Mahmoud 37
MIDlet Packaging
Java Application Descriptor (JAD) file provides info:
Configuration properties Pre-download properties
Size, version, storage requirements
![Page 38: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/38.jpg)
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
![Page 39: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/39.jpg)
Qusay H. Mahmoud 39
Example MIDlet: Testing
emulator –Xdescriptor first.jad
![Page 40: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/40.jpg)
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
![Page 41: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/41.jpg)
Qusay H. Mahmoud 41
Simplifying the Development Effort
Sun Java Wireless Toolkit for CLDC
![Page 42: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/42.jpg)
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)
![Page 43: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/43.jpg)
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
![Page 44: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/44.jpg)
44
BlackBerry
To utilize BlackBerry-specific features, use BlackBerry APIs
Application lifecycle is different
![Page 45: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/45.jpg)
45
BlackBerry
Rest of code…
![Page 46: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/46.jpg)
46
MIDP APIs
MIDP specifies APIs for:
User Interface Networking (based on CLDC) Persistent Storage Others…(Game API, security, etc)
![Page 47: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/47.jpg)
47
MIDP Packages
MIDP 1.0 java.lang Java.util Java.io Javax.microedition.io Javax.microedition.lcdui Javax.microedition.midlet Javax.microedition.rms
![Page 48: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/48.jpg)
48
MIDP Packages
MIDP 2.0 Javax.microedition.lcdui.game Javax.microedition.media Javax.microedition.media.control Javax.microedition.pki
![Page 49: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/49.jpg)
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
![Page 50: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/50.jpg)
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
![Page 51: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/51.jpg)
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)
![Page 52: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/52.jpg)
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);
![Page 53: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/53.jpg)
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
![Page 54: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/54.jpg)
54
MIDP UI Class Diagram
Major classes and interfaces:
![Page 55: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/55.jpg)
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);
![Page 56: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/56.jpg)
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);
![Page 57: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/57.jpg)
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);
![Page 58: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/58.jpg)
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);
}
}
![Page 59: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/59.jpg)
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()}
![Page 60: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/60.jpg)
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
![Page 61: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/61.jpg)
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);
![Page 62: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/62.jpg)
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
![Page 63: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/63.jpg)
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(); } }}
![Page 64: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/64.jpg)
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; }
![Page 65: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/65.jpg)
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
![Page 66: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/66.jpg)
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)); } }
![Page 67: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/67.jpg)
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
![Page 68: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/68.jpg)
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
![Page 69: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/69.jpg)
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
![Page 70: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/70.jpg)
70
Connection Interfaces
MIDP 1.0
![Page 71: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/71.jpg)
71
MIDP 2.0
![Page 72: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/72.jpg)
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”);
![Page 73: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/73.jpg)
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
![Page 74: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/74.jpg)
74
MIDP Connectivity
It provides support for HTTP (HttpConnection)
Why? HTTP can be implemented using IP protocols or non-IP protocols
![Page 75: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/75.jpg)
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”);
![Page 76: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/76.jpg)
76
Invoking Remote Applications
A MIDlet may invoke remote applications:
Fetching a page Invoking a CGI script (GET or POST
method) Invoking a Servlet
![Page 77: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/77.jpg)
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);}
![Page 78: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/78.jpg)
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());
![Page 79: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/79.jpg)
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
![Page 80: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/80.jpg)
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
![Page 81: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/81.jpg)
81
MIDP RMS Methods
Record StoreopenRecordStore, closeRecordStore, listRecordStore, deleteRecordStore, getRecordSize, getNumRecords
Record DataaddRecord, deleteRecord, getRecord, setRecord, getRecordSize
Record SelectionRecordEnumeration, RecordFilter, RecordComparator
![Page 82: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/82.jpg)
82
RMS: Record Stores
To open a record store: RecordStore db =
RecordStore.openRecordStore(“myDB”, true);
To close a record store: db.closeRecordStore();
![Page 83: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/83.jpg)
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);
![Page 84: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/84.jpg)
84
Building a Stock Database
See appendix for source code: Stock.java StockDB.java QuotesMIDlet.java
![Page 85: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/85.jpg)
85
StockQuotes MIDlet
![Page 86: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/86.jpg)
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
![Page 87: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/87.jpg)
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)
![Page 88: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/88.jpg)
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…
![Page 89: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/89.jpg)
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
![Page 90: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/90.jpg)
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
![Page 91: Introduction to Mobile Application Development](https://reader035.vdocuments.net/reader035/viewer/2022081413/548b71feb479599d608b46af/html5/thumbnails/91.jpg)
91
Thank you