RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Mobilize Your Java Applications with Java ME Technologies : Page 3

Read this beginner's guide to extending an enterprise application to mobile devices with the Java ME technologies.

Taking a Photo
To use the camera, the first step is to use the locator (« capture:// video ») in the createPlayer() method. After getting the control « VideoControl », you can start the display by calling the start() method. (See Listing 3 for the complete code for taking a photo.) Pressing the FIRE key starts a thread, in which the mobile phone takes a snapshot by calling the getSnapshot() method. When the picture is taken, data are stored in a byte array (data[]). Then you can convert this array into an image you can display.

To tailor the code to a specific device, you have to specify the encoding. The encodings list depends on the model of the mobile device you're targeting. You can get this list by using the FormEncodings class, which displays the encodings list supported on your target device. The split() method splits the encodings list with a space separator (see Listing 4).

Sending Data via HTTP
To send data via HTTP, you again have to use a thread. You open and send data in the run() method. During the upload process, you can use a FormWait class to display a gauge. To upload a photo, you have to use the POST method (HttpConnection.POST). The data to send are stored in the dataToSend byte array and sent in the « os.write » line.

The web server returns the content length, and then you read data with the read() method (see Listing 5 for the complete code).

A Foundation to Build On
With all the previous steps completed, you have built the main structure of the mobile application, complete with a deployment server, a server-side gateway script, and a server-side database. If you decide to build upon this skeleton and implement a more robust application, you should take into account are few important factors not discussed in this article:

  • Extremely low memory and communication problems with the mobile network
  • Support for specific behaviors, such as variations of the locator to take snapshots and not returning content length from the web server.
  • Porting the mobile application to each mobile device model you support

Bruno Delb, the author of the first French book about J2ME, is the founder of Net Innovations and Unified Mobiles. Unified Mobiles has created the concept of unified mobile applications development, based on UMAK (Unified Mobile Application frameworK). UMAK is a complete framework to facilitate and accelerate the development of multiplatform applications (J2ME, DoJa, and Web applets). It's based on a very detailed knowledge base of devices, a Java testing suite, a productivity tools suite, and on a configuration engine to take into account each feature of each device model.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date