Manage your account and access personalized content. Sign up for an Oracle Account. Access your cloud dashboard, manage orders, and more.
Learn how easy it is to update the text, images, and source code for Java ME applications. Updating a Java Platform, Micro Edition Java ME application involves updating static data, such as text and images, as well as updating code components of the application.
In this article, I develop a sample application that illustrates how to update an application. The article starts with the basics—updating simple text strings—and then moves to updating images. Finally, the article shows the easiest way to update the core application files, which Java ME makes quite easy.
However, this ease can come at a price in terms of extra network traffic. The complete source code for the application described in this article can be downloaded here. The application has two elements: Selecting Menu shows the three actions that can be performed, as shown in Figure 2.
The Update Text menu item will check with a background server to see whether an update is available for the text portion of the application. Update Image will check to see whether the image needs to be updated.
Finally, Update Code will update the whole application—the text, the image, and the underlying code. The application is a simple MIDlet that has three basic commands and two visual components.
We set up the basic display elements and hook up the commands in the constructor, as shown in Listing 1. There is nothing remarkable about this code. These are the elements that we are going to upgrade. Then Download hook up messenger for java commands are added: Notice that the Exit command is set at a separate level from the update commands, so the update commands are grouped together when you select Menu.
Finally, the current MIDlet is set as the command listener for all the commands so it can handle the callbacks.
Code for Handling the UpdateText Command. When the command handler for this code starts, it creates a new thread and contacts the server the server holds the text, image, and code files.
At this point, we are interested only in checking for text-based updates, so we use the ContentConnection class instead of the usual HttpConnection class. With the help of this class, we check for the presence of an updatedText. If such a file is found, we read it, using a DataInputStream, into a byte array and convert it into a string. At any stage, if an error occurs, the error handler takes over. If the file is found, its contents are read, and the contents are not the same as the existing text, we modify the text in StringItem.
We have updated our text! The next step is to see how we can update the image. Updating the image is not very different from Download hook up messenger for java the text. Listing 3 shows how it is Download hook up messenger for java. As you can see, instead of using the ContentConnection, we use the HttpConnection class to update the image. If we find an image and its size is greater than 0, we download it into a byte buffer using a DataInputStream instance.
It is expected that an update process on the server would keep the text file or the image file only if updates were available.
This would be an offline process and part of the update routines. We could modify our code to notify the user that there are no updates available, instead of letting the error handler handle it. Finally, we come to one of the easiest parts of the update process.
Updating the core code itself or rather, updating the whole MIDlet and its associated files. Why is this the easiest part? Because by using an in-built function, we can request that the MIDlet update itself.
This is useful when you have made several modifications to the code and associated logic and, therefore, non-static data needs to be updated. The downside is that the update process can be network-expensive. We use the method platformRequest String to update the code itself. This method is provided by the MIDlet class, and it is used to request that the device on which it is running handle the provided URL.
For example, if this method is called with the URL of an image, the handling device would need to call up an image viewer to view the image provided by the URL.
By providing a URL that ends in. Of course, user intervention is required to acknowledge the update process and to answer any pre-update questions, as shown in Figure 5. Once the user authorizes the update, the device downloads and updates the code.
This process happens without any more intervention from the user or the original MIDlet. Once the update has finished, the old MIDlet is removed from the device and the new one is installed.
Comprehensive download hook up messenger for java naked porn tube
After the install, the device will confirm whether the user wants to start the new MIDlet. All in all, the platformRequest String method of the MIDlet class makes it easy for the application developer to provide an in-built update mechanism for applications.
On the other hand, if you need to provide a mechanism for updating the entire source code, make sure you follow a valid update process on the server, and use platformRequest String with a URL that ends in jad to provide the updates.
This book explains how to add multimedia capabilities to Java technology-enabled phones. Vikram is also the author of the Jakarta Commons Online Bookshelfand he helps manage a free craft projects Web site. Home Skip to Content Skip to Search. Oracle Account Manage your account and access personalized content. Sign up for an Oracle Account Sign in.
Sign into Cloud Access your cloud dashboard, manage orders, and more. Sign Up—Free Trial Sign in. Oracle Technology Network Articles Java. Published December Downloads: The Application Flow Figure 1 shows an example application in action. Example Application The application has two elements: Possible Actions The Update Text menu item will check with a background server to see whether an update is available for the text portion of the application.
Coding the Layout The application is a simple MIDlet that has three basic commands and two visual components. Setting Download hook up messenger for java the Display Elements There is nothing remarkable about this code. Listing 2 shows the code for handling the UpdateText command: Code for Handling the UpdateText Command When the command handler for this code starts, it creates a new thread and contacts the server the server holds the text, image, and code files.