using j2me to create field force applications l.
Skip this Video
Download Presentation
Using J2ME to create Field Force Applications

Loading in 2 Seconds...

play fullscreen
1 / 29

Using J2ME to create Field Force Applications - PowerPoint PPT Presentation

  • Uploaded on

Using J2ME to create Field Force Applications. Chris Clark, MobileHWY, LLC. THE BUSINESS. The Mobility Business. Building wireless applications that people can use everyday to get their job done. Using cheap or existing hardware. $200 or less

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Using J2ME to create Field Force Applications' - nida

Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
the mobility business
The 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.
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.

mobile building blocks
Mobile 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.
mobile building blocks6
Mobile Building Blocks
  • GPS – 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)
mobile building blocks7
Mobile 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.

mobile building blocks8
Mobile 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 Bluetoothserial profile)
  • Tethered serial cable printing
mobile building blocks9
Mobile 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.

mobile development
Mobile Development


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


Development tools are not all the same.


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

several things to consider
Several Things to Consider
  • - 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.
  • - Find out early how you get your application on the device
getting some build tools
Getting Some Build Tools

Sun Microsystems – Wireless Toolkit 2.2

Blackberry Java Development Environment

Motorola iDen developer

EclipseME – J2ME plugin for Eclipse

it all starts with the midlet
It all starts with the MIDLET

public 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);




* Signals the MIDlet to terminate and enter the Destroyed state.


protected void destroyApp(boolean unconditional) {




* Signals the MIDlet to stop and enter the Paused state.


protected void pauseApp() { /* Do Nothing */ }

public void Show(Displayable d)





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);




creating your screens
Creating your screens

Creating 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);

creating your screens17
Creating your screens

There 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.

creating your screens18
Creating your screens

There are 4 types of objects you can use with setCurrent();

Form : Screen

You insert Items onto the Form using Form.append or Form.insert

Alert : Screen

Alerts 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 : Screen

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

List : Screen

A list is for displaying a list of choices. Lists can contain images.

creating your screens19
Creating your screens

There are several Items you can add to your Form.

ChoiceGroup : Item

Similar to List except in a Form.

DateField : Item

For presenting calendar (date and time) information.

Gauge : Item

Bar graph

ImageItem : Item

Add image

StringItem : Item

Add string

TextField : Item

Input text box with optional formatting constraints.

processing commands
Processing Commands

Your class needs to support the CommandListener interface

public class scrnCreditCard implements CommandListener {

You need to define the command

private 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) {




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;

data storage
Data Storage

javax.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.

data storage22
Data Storage


public void getRecord( int recordId );


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


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


public void deleteRecord( int recordId );


StringBuffer text = new StringBuffer();

HttpConnection c =

(HttpConnection), Connector.READ_WRITE, true);


int rc = c.getResponseCode();

if (rc == HttpConnection.HTTP_OK)


InputStream is = c.openDataInputStream();

int ch;

while((ch = != -1) {

text.append((char) ch);


} else {

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


String response = text.toString();

entity classes
Entity Classes

We 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(…);


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


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


gps mapping
GPS Mapping

Once 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 Strategies

Automation of MapPoint to create custom .NET Web services

Using Microsoft MapPoint Web Services

Using MapQuest Web Services

j2me connector
J2ME Connector

Whether 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.

j2me connector28
J2ME Connector

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

bluetooth serial printing
Bluetooth Serial Printing

BluetoothSerialPortInfo[] info = BluetoothSerialPort.getSerialPortInfo();

// Get first Bluetooth Serial Device registered with this mobile device

String bluetoothConnectionString = info[0].toString();

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

DataOutputStream outstream = sc.openDataOutputStream();