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