Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Mobilize Your Java Applications with Java ME Technologies : Page 2

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


advertisement
Building the Structure of the Application
The common procedure for deploying a mobile Java application is to use a WAP/XHTML site and insert a link to the application in a page on the site. Users then download the application by opening this link. A developer can send this link by SMS (Short Message Service) as well.

The gateway script for the project has to receive data from and return data to the mobile application. This gateway script can be written in Java, PHP, ASP, or any such scripting language. The script will store data in a traditional database with SQL requests.

The application uses the Mobile Media API (MMAPI) to enable the picture-taking function on the device, but not all mobile devices support MMAPI for taking a pictures. To find out whether or not a device supports this feature, you can use this method:



public static boolean isSupported() { String supports = System.getProperty("supports.video.capture"); if (supports == null || !supports.equals("true")) return false; else return true; }

If it returns true, the device can take snapshots. If not, the mobile application will:

  • Store data
  • Display data
  • Take a photo
  • Send the photo to a web server

The server will have to receive data sent by the mobile application, store them in a database, and then return data to the mobile application.

Storing Data
To save data, you have to use RMS (Record Management System). As a persistent storage space, RMS ensures that the stored values remain even when the mobile phone is turned off. Data are stored in a recordstore (« data », in this example), which is a collection of records. Each record is a byte array. Listing 1 is an example of the source code for storing data.

Data are stored in the ConfigurationData class. The getData() method returns the data, and the setData() method stores the data. The setDefaultValues() method returns the default value.

The main methods are save() and read(). To save data, you open the recordstore « data ». If it fails, the recordstore doesn’t exist and you have to add the record. If the record exists, you update the record. To read data, you open the recordstore. If it doesn’t exist, you create one. If there is no record or if you have just created one, you just return the default value. Otherwise, you return the first record of the record store.

Displaying Data
To use the stored data, you use a form. In this example, you display the data in a user component, a TextField. To initialize its value, you call the intialize() method. This method calls the stored data by calling getData().

When the data is updated in the form, the user activates the « OK » command, which calls the returnValues() method. The first step is to save the data in the storage class (« ConfigurationData »). Then you save and reload data in the recordstore.

If the user activates the « Cancel » command, you open the screen « menu ». Listing 2 shows the code.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap