using j2me to create field force applications chris clark, mobilehwy, llc

29
Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Upload: rebecca-carpenter

Post on 11-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Using J2ME to create Field Force

Applications

Using J2ME to create Field Force

Applications

Chris Clark, MobileHWY, LLC

Page 2: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

THE BUSINESSTHE BUSINESS

Page 3: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

The Mobility BusinessThe Mobility Business

Building wireless applications that people can use everyday to get their job done.

- Using cheap or existing hardware. $200 or less

- Providing access to legacy data in a mobile environment

- Using the Internet to get data to and from the mobile devices. $50/mth or less.

- Leveraging GPS and Bluetooth to make the devices more capable.

Page 4: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

What do customers want?What do customers want?

Legacy Integration – Integrating with backend systems to make data available to mobile applications.

GPS –Tracking of people, places and things using GPS coordinates.

Credit Card Processing – Creating mobile POS.

Printing – Bluetooth printing capability for receipts.

Broadcast Messaging – Sending broadcast messages to mobile devices.

Bluetooth Camera – To take pictures

Bluetooth Compass – To not only determine location but direction you are facing.

Page 5: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Mobile Building BlocksMobile Building Blocks

Legacy Integration

- Database access: SQL Server, Oracle, mySQL, Btrieve, Foxpro, ASCII Flat file

- Mainframe screen scraping: Navigating 3270 screens.

- Web screen scraping: Automation of web sites.

- TCP Socket communication to host process.

- VoiceXML: To automate Interactive Voice Response systems.

Page 6: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Mobile Building BlocksMobile Building BlocksGPS – Global Positioning System

- Location tracking: Reading GPS coordinates from mobile device.

- Driving Directions – Get directions from where you are to where you need to go.

- Route Navigation – Use GPS updates from the device to determine if route is being followed. Also can track speed and heading.

- Dynamic mapping of field force – plot all data points for last known location of devices.

- Proximity searching – search for locations near your current position. i.e. Location Based Services (LBS)

Page 7: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Mobile Building BlocksMobile Building Blocks

Credit Card Processing

Using Bluetooth a mobile device can attach to a credit card swipe reader.

All credit cards conform to the same specification for storing credit card information on Track 1.

%/1/B<creditcardnumber>^<lastname>/<firstname>^<expiration year><expiration month><otherdigits>CRLF

If you can read one, you can read them all.

Page 8: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Mobile Building BlocksMobile Building Blocks

Printing

Customers want to print a variety of information.

Printing on a mobile device involves using serial IO to connect to the printer.

Then sending printer Esc codes to the printer to format the information for display.

There are 2 flavors of serial printing.

- Bluetooth printing (uses Bluetooth serial profile)

- Tethered serial cable printing

Page 9: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Mobile Building BlocksMobile Building Blocks

Broadcast Messaging

Customers have a high demand for being able to send out broadcast messages to their field force.

Broadcast messaging uses a queuing server which contacts each device seperately and confirms delivery of the message.

Primarly socket communications to the device’s IP address from a centralized server.

Page 10: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

THE TECHNOLOGYTHE TECHNOLOGY

Page 11: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Mobile DevelopmentMobile Development

RULE #1

Using the device simulator is no indication of how the application is going to run on the device.

RULE #2

Development tools are not all the same.

RULE #3

You are breaking new ground. There will be issues that will require trial and failure

Page 12: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Several Things to ConsiderSeveral Things to ConsiderBUILD

- Always build for optimal performance. It’s not a PC.

- There will be code differences needed sometimes for different devices. Some java will not pass bytecode verification on the device.

TEST

- Know your carrier requirements for testing.

- Make sure you test on the device.

DEPLOY

- Find out early how you get your application on the device

Page 13: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Getting Some Build ToolsGetting Some Build Tools

Sun Microsystems – Wireless Toolkit 2.2

http://java.sun.com/products/j2mewtoolkit/

Blackberry Java Development Environment

www.blackberry.com/developers

Motorola iDen developer

http://idenphones.motorola.com/idenDeveloper/

EclipseME – J2ME plugin for Eclipse

http://eclipseme.sourceforge.net/

Page 14: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

It all starts with the MIDLETIt all starts with the MIDLETpublic class CreditCardDemo extends MIDlet {

public Display display;

/** * Signals the MIDlet to start and enter the Active state. */ protected void startApp() { display = Display.getDisplay(this); scrnCreditCard CreditCardForm = new scrnCreditCard(this); CreditCardForm.Show(); }

/** * Signals the MIDlet to terminate and enter the Destroyed state. */ protected void destroyApp(boolean unconditional) { notifyDestroyed(); }

/** * Signals the MIDlet to stop and enter the Paused state. */ protected void pauseApp() { /* Do Nothing */ }

public void Show(Displayable d) { this.display.setCurrent(d); }}

Page 15: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Understanding startApp()Understanding startApp()Applications will suspend sometimes because of incoming phone calls.

startApp() will be called again when this happens, so make sure you restore to the proper screen. Don’t assume that every time startApp is called you should login.

Normally, I keep a public variable around called display as part of the midlet class. I initialize display to a value when the application first starts. I check the value and restore to the proper state.

Here is a modified startApp()

protected void startApp() {if(display != null) {

/* Do nothing, will restore the screen they were on */} else {

display = Display.getDisplay(this); scrnCreditCard CreditCardForm = new scrnCreditCard(this); CreditCardForm.Show();

} }

Page 16: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Creating your screensCreating your screensCreating screens are pretty straight forward.

You need a reference to the MIDlet’s display object.

Display display = Display.getDisplay(MIDlet m);

With this display object you can change the screen by calling setCurrent.

display.setCurrent(Displayable display);

Page 17: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Creating your screensCreating your screensThere are 2 Displayable objects

Screen : Displayable

Screen is what you should think about when you are designing form based applications. This is primarily what we use.

Canvas : Displayable

Canvas is more centered toward games or custom controls. With Canvas also comes the ability to read the devices keyboard through events. This is really designed more toward games.

Page 18: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Creating your screensCreating your screensThere are 4 types of objects you can use with setCurrent();

Form : ScreenYou insert Items onto the Form using Form.append or Form.insert

Alert : ScreenAlerts are similar to VB message box. They provide quick notifications as to what the application is doing. As with message box there are different types of Alerts (Alarm, Confirmation, Error, Info, Warning).

TextBox : ScreenA textbox is similar to HTML <textarea>. This is for multi-line text entry.

List : ScreenA list is for displaying a list of choices. Lists can contain images.

Page 19: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Creating your screensCreating your screensThere are several Items you can add to your Form.

ChoiceGroup : ItemSimilar to List except in a Form.

DateField : ItemFor presenting calendar (date and time) information.

Gauge : ItemBar graph

ImageItem : ItemAdd image

StringItem : ItemAdd string

TextField : ItemInput text box with optional formatting constraints.

Page 20: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Processing CommandsProcessing CommandsYour class needs to support the CommandListener interfacepublic class scrnCreditCard implements CommandListener {

You need to define the commandprivate static Command CMD_EXIT = new Command("EXIT", Command.ITEM, 1);

You need to implement the CommandListener interface public void commandAction(Command c, Displayable d) { if (c == CMD_EXIT) { app.destroyApp(true); } }

If you intend to access your Form’s Items within the commandAction, you need to define your Item at the class level.private StringItem progressLabel;

Page 21: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Data StorageData Storagejavax.microedition.rms.RecordStore – Record Management System

J2ME provides a really basic storage capability for storing strings called a RecordStore.

A database is a stretch. Think of being able to store strings in a file and retrieve them based on a record ID.

In practical use, we create ENTITY CLASSES that are capable of going to and from strings.

We create a class with all it’s properties and provide:

- parse() method for retrieving the state of the object from a string.- toString() method for storing the state of the object to a string.

Using this capability, we are able to effectively retrieve objects from the RecordStore and return them to their state.

Page 22: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Data StorageData StorageSELECTpublic void getRecord( int recordId );

INSERTpublic int RecordStore.addRecord( byte[ ] data, int offset, int numBytes ) ;

UPDATEpublic void setRecord( int recordId, byte[ ] newData, int offset, int numBytes );

DELETEpublic void deleteRecord( int recordId );

Page 23: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

HTTPHTTPStringBuffer text = new StringBuffer();

HttpConnection c = (HttpConnection) Connector.open(getUrl, Connector.READ_WRITE, true);

c.setRequestMethod(HttpConnection.GET);

int rc = c.getResponseCode();

if (rc == HttpConnection.HTTP_OK) {

InputStream is = c.openDataInputStream();int ch;while((ch = is.read()) != -1) {

text.append((char) ch);}

} else {throw new IOException("HTTP response code: " + rc);

}

String response = text.toString();

Page 24: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Entity ClassesEntity ClassesWe heavily use ENTITY CLASSES for the data operations in the mobile device.

After retrieving data through some method of HTTP.

Create a new instance of your ENTITY CLASS

Set the properties of the ENTITY CLASS from the data you have retrieved through HTTP. A simple method maybe to parse through some XML.

After you have the state of your ENTITY CLASS. Convert this state to a string by calling the toString() method.

Store this string in your RecordStore using RecordStore.add(…);

Page 25: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

GPSGPSGPS support is going to be dependant on device. JSR129 or MAYBE NOT

JSR129 EXAMPLE try {

// Lots of Criteria options are available per spec, few supported Criteria myCriteria = new Criteria();

LocationProvider myLocProv = LocationProvider.getInstance(myCriteria);

// If no result could be retrieved, a LocationException is thrown. Location myLocation = myLocProv.getLocation(-1);

// returns a QualifiedCoordinates object which also has accuracy information // inherits from Coordinates object QualifiedCoordinates myCoordinates = myLocation.getQualifiedCoordinates();

// get the Coordinates from the QualifiedCoordinates double myLat = myCoordinates.getLatitude(); double myLng = myCoordinates.getLongitude();}catch (LocationException locex){ // Could not get a fix}

Page 26: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

GPS MappingGPS MappingOnce you have the coordinates of the device. Most of the GPS features are implemented using other services.

A dynamic mapping example.Tracking the device may require you to send the coordinates to a centralized server and time and date stamp them into a database. A web based system may retrieve the coordinates and display them to the user on a map. Lot of technologies may be in play here with the mobile device being the most simple of the technologies employed.

Mapping StrategiesAutomation of MapPoint to create custom .NET Web services

Using Microsoft MapPoint Web Services

Using MapQuest Web Services

Page 27: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

J2ME ConnectorJ2ME ConnectorWhether you are doing serial printing using a tethered cable to the device or Bluetooth. The process is pretty much the same.

J2ME offers a Connector architecture for communications. Serial communications is just about the same as HTTP except for the ConnectionString.

If you know how to work with Streams in J2ME you can communicate to most anything.

In serial communication, you are primarily dealing with COM0. String connstring = "comm:0;baudrate=19200;parity=n;databits=8;stopbits=1;flowcontrol=s/s";

Bluetooth varies and most connection strings appear to be proprietary based on the hardware. In some cases the connection string is even abstracted through classes as you will see in the next example.

Page 28: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

J2ME ConnectorJ2ME ConnectorString connstring = "comm:0;baudrate=19200;parity=n;databits=8;stopbits=1;flowcontrol=s/s";

Page 29: Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC

Bluetooth Serial PrintingBluetooth Serial PrintingBluetoothSerialPortInfo[] info = BluetoothSerialPort.getSerialPortInfo();

// Get first Bluetooth Serial Device registered with this mobile deviceString bluetoothConnectionString = info[0].toString();

StreamConnection sc = (StreamConnection) Connector.open(bluetoothConnectionString, Connector.READ_WRITE);

DataOutputStream outstream = sc.openDataOutputStream();

outstream.write(this.data.getBytes());

outstream.flush();

outstream.close();

sc.close();