1 / 29

Using J2ME to create Field Force Applications

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

Sharon_Dale
Download Presentation

Using J2ME to create Field Force Applications

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. THE BUSINESS

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

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

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

  6. 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)

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

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

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

  10. THE TECHNOLOGY

  11. Mobile 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 

  12. Several Things to Consider • BUILD • - 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

  13. Getting 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/

  14. 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); 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); } }

  15. 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(); } }

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

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

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

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

  20. 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) { 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;

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

  22. Data Storage SELECT public void getRecord( int recordId ); INSERT public int RecordStore.addRecord( byte[ ] data, int offset, int numBytes ) ; UPDATE public void setRecord( int recordId, byte[ ] newData, int offset, int numBytes ); DELETE public void deleteRecord( int recordId );

  23. HTTP StringBuffer 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();

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

  25. GPS GPS 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 }

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

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

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

  29. 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.open(bluetoothConnectionString, Connector.READ_WRITE); DataOutputStream outstream = sc.openDataOutputStream(); outstream.write(this.data.getBytes()); outstream.flush(); outstream.close(); sc.close();

More Related