36
511, MIDP Programming for Wireless Devices MIDP Programming for Wireless Devices Jeffery Hackert—Nextel Mark Karmelich—Quantum SI Jon Strabala—Quantum SI

511, MIDP Programming for Wireless Devices MIDP Programming for Wireless Devices Jeffery Hackert—Nextel Mark Karmelich—Quantum SI Jon Strabala—Quantum

Embed Size (px)

Citation preview

511, MIDP Programming for Wireless Devices

MIDP Programming for Wireless Devices

Jeffery Hackert—NextelMark Karmelich—Quantum SIJon Strabala—Quantum SI

511, MIDP Programming for Wireless Devices2

MIDP Programming—Topics

• Introduction to MIDP– Java™ technology/J2ME™ platform Vision—

How Does MIDP fit In?– Developer Opportunities—why use MIDP?– API—what can I do with MIDP?

• Demonstration– Java technology-based code (“Java code”) and

Running Examples of “MIDlets”– Strengths, Weaknesses, and Limitations of MIDP

• Implementation– Present Real-world Applications, Market Needs– Future of MIDP and Java technology for

wireless platforms

511, MIDP Programming for Wireless Devices3

Learning Objectives

• Understand MIDP’s value and purpose for the Java™ 2 Platform, Micro Edition (J2ME™)

• Learn how to write a basic MIDlet• Be able to implement key elements of MIDP

API– GUI, Timers, Networking, Storage

• Understand where MIDP is at today and where the Java and J2ME technologies are headed

• Learn MIDP limitations and ways to work around them

511, MIDP Programming for Wireless Devices4

Speaker’s Qualifications

• Jeffery Hackert is a Sr. Systems Integrator for Nextel Communications Inc.

• Mark Karmelich is a Sr. Programmer and VP of Engineering of Quantum SI Inc.

• Jon Strabala is a Sr. Programmer and CTO of Quantum SI Inc.

• All speakers have implemented and deployed many successful Java™ technology-based solutions in the wireless and non-wireless industry sectors

511, MIDP Programming for Wireless Devices5

Java™ Technology and the Wireless Space

*source: The ARC Group

• 20% of Nextel Customers Use Data Services• Number of Mobile Data Users will total 1.2 billion

by 2005*• The Java and J2ME technologies are

driving a revolution in smart, portable, networked devices

• For the first time, cell phone manufacturers are allowing any vendor to dynamically install software on phone

• MIDP brings Java technology back to its roots (“Oak”: smart networking for small appliances)

511, MIDP Programming for Wireless Devices6

Hierarchy—Where Does MIDP Fit In?

• Configurations and Profiles– J2ME—The Java 2 Platform, Micro Edition– CLDC—Connection Limited Device

Configuration– MIDP—Mobile Information Device Profile

MIDP Applications

OEM-SpecificApplications

Native Applications

CLDC

MID

Native System Software

MIDP

OEM-SpecificClasses

511, MIDP Programming for Wireless Devices7

MIDP is first CLDC Profile

• MIDP Profile: cell phones, pagers, etc. (very limited resource devices)

• The MIDP is currently the only implemented profile

• Motorola i85 is first MIDP device to market (others to follow quickly!)

511, MIDP Programming for Wireless Devices8

MIDP Device Specification

• MIDP Minimum Device Specs– 1-bit grayscale 96 x 54 (W x H) pixel display– Memory

• 128K for MIDP Components, Non-volatile• 8K for RMS, Non-volatile• 32K for “Java heap”

• Note: Motorola i85s Device Specs– 2-bit grayscale 110 X 100 (W x H) pixel display– 256 K heap– 383k of storage available for MIDlets

511, MIDP Programming for Wireless Devices9

MIDlet API

• Classes must extend “MIDlet” class to use MIDP

• Conceptually similar to Applets, but very limited

• Two GUI APIs:– “High Level” Basic GUI: List, Textbox, Alert– “Low Level” GUI: Canvas Drawing

• Simple persistent storage mechanism (RMS)• Jar-based MIDlet “suites” can share data• Limited support for Networking,

Threads, Timers

511, MIDP Programming for Wireless Devices10

“High Level” GUI vs. “Low Level” GUI

• High Level GUI– Standard Business applications

– Simple “Form” to contain GUI components

– Minimal set of available components• List, Alert, Textbox, etc.

– High Level component-based Events

• Low Level GUI– Full Canvas drawing methods

– Drawing of shapes, strings, images

511, MIDP Programming for Wireless Devices11

MIDlet Lifecycle

• MIDlet States:– Started

– Paused

– Destroyed

• JAM: The Java™ Application Manager API

• The JAM API Controls MIDlet state

• MIDlet can “request” via the JAM API to change state

511, MIDP Programming for Wireless Devices12

MIDlet Lifecycle Methods

javax.microedition.midlet.MIDlet

public void startApp() {}

public void pauseApp() {}

protected abstract void destroyApp(boolean unconditional) {}

Note similarity to Applet Lifecycle:java.applet.Applet

public void init(){}

public void start(){}

public void stop(){}

public void destroy(){}

511, MIDP Programming for Wireless Devices13

MIDlet Examples

• Three MIDlet Examples to highlight MIDP features

• MIDlet #1: Basic MIDlet, high-level GUI, Timers

• MIDlet #2: HTTP and RMS

• MIDlet #3: Jini™ network technology capabilities

511, MIDP Programming for Wireless Devices14

MIDlet #1—Forms, Alerts, Timers

User chooses MIDlet, sees initial screen, then gets “Alert” message

“Next” softkey leads to new form, which includes Timer class to go to final page

511, MIDP Programming for Wireless Devices15

MIDlet #1—Required MIDlet Methods

import javax.microedition.midlet.*

public class IMF1Midlet extends MIDlet {

public IMF1Midlet() { // initialize stuff here }

public void startApp() { // JAM says start App, may get called multiple times }

public void destroyApp(boolean unconditional) { // MIDlet over -- close any network connections, save // RMS data. Warning, if destroyApp() takes too long, // JAM may kill MIDlet before method is done! }}

511, MIDP Programming for Wireless Devices16

MIDlet #1—pauseApp()

// JAM has “paused” the MIDlet (perhaps a phone // call came in).

// TIP: Keep requesting to be resumed until // we get the display back:

public void pauseApp() {

while (!this.display.getCurrent().isShown()) {

resumeRequest();

try {

Thread.sleep(5000); // 5 seconds

} catch (InterruptedException ie) {}

} }

511, MIDP Programming for Wireless Devices17

MIDlet #1—Forms, Buttons

public class MyForm extends Form implements CommandListener{ public void init() { // called when ready to display setCommandListener(this); // for button clicks

this.nextB = new Command(“Next”,Command.SCREEN, 1); this.addCommand(nextB); // set up a “next” button

// create from image stored in MIDlet jar file Image image = Image.createImage(“/imf/pics/x.png”); append(image); // place image in form append(“Good Morning, Mr. Phelps”); // place text}

public void commandAction(Command c, Displayable d) { // process the “next” button for next screen…}

511, MIDP Programming for Wireless Devices18

MIDlet #1—Timers, Alerts

public class IMFTimerTask extends TimerTask {

// set a class variable in the constructor // to call back the main MIDlet class later private MyMIDletInterface callback;

public void run() { // called when timer goes off

// perform action, e.g., put up Alert using an // “interface” callback to main MIDlet, passing // IMFAlert that extends Alert, displays image: callback.showAlert(new IMFAlert(“boom.png”)); }}

// to use the IMFTimerTask, create a Timer:Timer timer = new Timer();timer.schedule(new IMFTimerTask(), 5000); // 5 secs

511, MIDP Programming for Wireless Devices19

Network Protocols

• MIDP Supported Network Protocols– HTTP– Sockets– DataGrams

• Generic Connection Framework– CDLC’s replacement of

java.net/java.io– Simple connections

across wireless– MIDP’s extension: HttpConnection

Connection

DatagramConnection

Stream Connection Notifier

Output Connection

Input Connection

Stream Connection

Content Connection

511, MIDP Programming for Wireless Devices20

Storage—Record Management System

• MIDP Method of local storage: RMS– Data is in form of “records”– Add, Delete, Get methods available– No java.io.File support, JDBC™ API,

etc—only RMS• Features

– Data Storage persists through MIDlet invocations– Different MIDlets can share RMS data ONLY if in

same MIDlet suite!– RMS is not thread safe between

threads in a MIDlet

511, MIDP Programming for Wireless Devices21

MIDlet #2—HTTP and RMS

HTTP: fetch encrypted message.

RMS: set/get crypto “key” from local storage.

Unscramble message and display

511, MIDP Programming for Wireless Devices22

MIDlet #2—HTTP

private StreamConnection conn;private InputStream stream;

public class IMF2Midlet extends MIDlet {

public String getSecretMessage(String url) { conn =(StreamConnection)Connector.open(url); stream = conn.openInputStream(); // read input stream into String variable String text = getTextFromStream(stream); stream.close(); conn.close(); return text; }

}

511, MIDP Programming for Wireless Devices23

MIDlet #2—RMS

// open a record store, create if necessary RecordStore mydb = RecordStore.openRecordStore(name, true);

// write to a stream, then add a record ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream stream = new DataOutputStream(baos); stream.writeInt(someIntegerValue); stream.writeUTF(someString); byte [] b = baos.toByteArray(); int recordID = mydb.addRecord(b, 0, b.length);

b = mydb.getRecord(recordID); // fetch a record

mydb.deleteRecord(recordID); // delete a record

511, MIDP Programming for Wireless Devices24

Java™ Servlet API/Jini™ Network Technology Bridge (“Servlet/Jini Bridge”)

• MIDlets cannot do Jini technology directly– No support for Reflection

– No ability to dynamically download and run Java programming language classes over wireless*

• MIDP can simulate Jini technology by talking to the “Jini proxy servlet”– Simple HTTP requests, supported by MIDP

– Unique ID for device, possibly stored in RMS

– Devices not based on Jini technology can thus participate in a Jini technology-enabled network

– *OTAP will allow downloads, but not dynamic classloading

511, MIDP Programming for Wireless Devices25

MIDlet #3—Servlet/Jini Bridge

Send message to “Jini Server” via Proxy

“JINI Server” finds another registered phone/ MIDlet, delivers message

511, MIDP Programming for Wireless Devices26

Real-world Business Apps

• MIDP provides functions above and beyond WAP– Local Storage and Local Computation– Complete Java platform control of GUI– Background Thread processing

• Sample Real-world Business App– Customer Support in field with MIDP phones– Jini technology registration of support

team members– Support requests are routed and assigned based on

team availability, expertise, and interactive feedback from on-line members

511, MIDP Programming for Wireless Devices27

API Summary

• What we have seen– MIDlet lifecycle and JAM API Control

– High Level and Low Level GUI

– Forms, Timers, and Alerts

– Networking

– RMS for persistent data store

– Example for simulating Jini technology

• What we hope to see!– Full Jini technology support via a

standard proxy API

511, MIDP Programming for Wireless Devices28

MIDP Issues

• Thread Limitations– No Thread Groups or Daemon Threads

– MIDlets begin to slow at around 10–12 threads

– You must synchronize multiple thread access to RMS

• Only one MIDlet in suite can run at once

• Network Limitations (2 connections at once)

• Limited Security and Authentication (Support for SSL just announced)

511, MIDP Programming for Wireless Devices29

Implementation

• Installing and Running MIDP code on your device– Compile on PC/Workstations

– Package into JAR files

– Load into Device

– Forte™ for Java™ IDE for MIDP development

511, MIDP Programming for Wireless Devices30

Packaging

• “JAD”—Java™ Technology Application Descriptor– *MIDlet-Name: IMF1Midlet– *MIDlet-Version: 1.0.0– *MIDlet-Vendor: Nextel Communications and

Quantum SI Inc.– MIDlet-Description: Impossible Mission Force MIDlet– MIDlet-Info-URL:

http://www.quantumsi.com/developer/midlets/– *MIDlet-Jar-URL: imf.jar– *MIDlet-Jar-Size: 1063– MicroEdition-Profile: MIDP-1.0– MicroEdition-Configuration: CLDC-1.0– MIDlet-1: IMF1Midlet,/imf.png, imf.IMF1Midlet

*required

511, MIDP Programming for Wireless Devices31

Installer—Loader

• Application Installer/Deinstaller for the Java™ platform– Moves jar contents to flash

– Second verification step crosschecks stack map

• Application Loader for the Java platform– Only able to load via serial port

– As of 5/2001 able to download classes over wireless

511, MIDP Programming for Wireless Devices32

The Future of Java™ Technology in Wireless Space

• Full Jini™ technology via a Proxy API:– Seamless integration of mobile devices in a

Jini technology-enabled network– Enterprise/Server applications with Jini

technology/MIDP integrated components• Expanded feature sets

– Tie-in with phone dialing/audio capabilities– Integration with on-board components

• Auto-dial• Stored phone numbers• Phone settings, etc.

511, MIDP Programming for Wireless Devices33

Summary

• MIDP extends the reach of wireless devices– Well known language– Open API and Community Process

• MIDP is a major component in the vision for the Java™ 2 Platform, Micro Edition (J2ME™)– Seamless network of interconnected devices– Unleashing power of mobile networked

computing• Great developer opportunities

– Tremendous business and gaming potential– Get your apps out!

511, MIDP Programming for Wireless Devices34

Resources and Contacts

• Email:– Jeff Hackert—[email protected]– Mark Karmelich—[email protected]– Jon Strabala—[email protected]

• Developer sites:– http://developer.nextel.com– http://www.motorola.com/idendev– http://www.quantumsi.com/developer– http://java.sun.com/products/midp

• This presentation will be available at:– http://java.sun.com/javaone

511, MIDP Programming for Wireless Devices