Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Picture this

View Web camera snapshots using a J2ME-capable phone

  • Print
  • Feedback

Mobile Information Device Profile (MIDP) provides a Java API for writing wireless applications that run in all mobile phones, two-way pagers, and PDAs that support MIDP. Another name for MIDP applications is MIDlets. Let's first cover some basics about working with MIDlets and Java.

A MIDlet is a Java class that extends the javax.microedition.midlet.MIDlet abstract class. First, a MIDlet extending the MIDlet abstract class must implement the startApp(), pauseApp(), and destroyApp() methods. Since all MIDP implementations must support images stored in PNG format, I use that format in this article's examples. If your Web cam does not support exporting files to PNG format, you'll need to convert them with a batch program. One such freeware program is IrfanView.

All MIDP implementations must provide support for the HTTP protocol. It's recommended to use HTTP, as this allows the application to be portable across all mobile information devices. The figure below shows an overview of Web cam-to-PDA connectivity.

Overview of Web cam-to-PDA connectivity

Set up your environment

For a development environment on your client machine, you will need three pieces of software:

  1. The Java 2 Platform, Standard Edition (J2SE). Be sure to set your environment variable as specified by the installation instructions.
  2. The Java 2 Platform, Micro Edition (J2ME) Wireless Toolkit. This toolset provides developers with the emulation environment and documentation to develop Java technology applications targeted at Connected Limited Device Configuration (CLDC)/MIDP-compliant mobile phones and PDAs.
  3. Web cam with image capture software. I used an X10 Web cam with the associated XRay software. Installation and configuration instructions come with the software. The XRay software takes snapshots on a periodic basis; the timeframe is customizable.


You will also need a code editor. You can use Notepad (for those working in Windows) or something fancier like jEdit.

You have multiple options for your server software. You can either use the Java 2 Platform, Enterprise Edition (J2EE) or Apache Tomcat. You will want to use Tomcat to follow this article's examples without modification. This article's source code has its roots from the PhotoAlbum example installed as part of the J2ME Wireless Toolkit. I've modified the code to fit our application needs more accurately.

Jump into the code

When the sample application you've created starts on your phone, the list of possible cameras is read from the Java Application Descriptor (JAD) file by calling the setupImageList() function:

 for (int n = 1; n < 100; n++) {
   String nthImage = "PhotoImage-"+ n;
   String image = getAppProperty(nthImage);
   if (image == null || image.length() == 0)
       break;
       String nthTitle = "PhotoTitle-" + n;
       String title = getAppProperty(nthTitle);
       if (title == null || title.length() == 0)
             title = image;
             imageNames.addElement(image);
             imageList.append(title, null);
 }


JAD files enable the device to verify things like whether the jar file is too big for the device and whether a new version of the MIDlet suite is already installed on the device without actually downloading the jar file. JAD files also provide the ability to add more cameras to the application without changing the byte code.

  • Print
  • Feedback

Resources