User Guide J2me Sony-Ericsson 2004
User Guide J2me Sony-Ericsson 2004
U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license
agreement and applicable provisions of the FAR and its supplements.
Sun, Sun Microsystems, the Sun logo, Java, J2ME and the Java Coffee Cup logo are trademarks or registered trademarks of Sun
Microsystems, Inc. in the U.S. and other countries. The Adobe logo and the PostScript logo are trademarks or registered trademarks
of Adobe Systems, Incorporated.
Products covered by and information contained in this service manual are controlled by U.S. Export Control laws and may be subject
to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end
users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities
identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is
strictly prohibited.
DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE
LEGALLY INVALID.
Copyright © 2004 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, Etats-Unis. Tous droits réservés.
Cette distribution peut comprendre des composants développés par des tierces parties.
Sun, Sun Microsystems, le logoSun, Java, J2ME et le logo Java Coffee Cup sont des marques de fabrique ou des marques déposées
de Sun Microsystems, Inc. aux Etats-Unis et dans d'autres pays.Le logo Adobe. et le logo PostScript sont des marques de fabrique ou
des marques déposées de Adobe Systems, Incorporated.
Les produits qui font l'objet de ce manuel d'entretien et les informations qu'il contient sont regis par la legislation americaine en
matiere de controle des exportations et peuvent etre soumis au droit d'autres pays dans le domaine des exportations et importations.
Les utilisations finales, ou utilisateurs finaux, pour des armes nucleaires, des missiles, des armes biologiques et chimiques ou du
nucleaire maritime, directement ou indirectement, sont strictement interdites. Les exportations ou reexportations vers des pays sous
embargo des Etats-Unis, ou vers des entites figurant sur les listes d'exclusion d'exportation americaines, y compris, mais de maniere
non exclusive, la liste de personnes qui font objet d'un ordre de ne pas participer, d'une facon directe ou indirecte, aux exportations
des produits ou des services qui sont regi par la legislation americaine en matiere de controle des exportations et la liste de
ressortissants specifiquement designes, sont rigoureusement interdites.
LA DOCUMENTATION EST FOURNIE "EN L'ETAT" ET TOUTES AUTRES CONDITIONS, DECLARATIONS ET GARANTIES
EXPRESSES OU TACITES SONT FORMELLEMENT EXCLUES, DANS LA MESURE AUTORISEE PAR LA LOI APPLICABLE, Y
COMPRIS NOTAMMENT TOUTE GARANTIE IMPLICITE RELATIVE A LA QUALITE MARCHANDE, A L'APTITUDE A UNE
UTILISATION PARTICULIERE OU A L'ABSENCE DE CONTREFACON.
Please
Recycle
Contents
Preface ix
1. Introduction 1
1.1 Quick Start 1
1.2 The Tools in the Toolkit 2
1.3 Toolkit Features 3
1.4 Supported Technology 3
Contents iii
3.1 Selecting APIs 19
3.2 Changing MIDlet Suite Attributes 21
3.3 Manipulating MIDlets 23
3.4 Using the Push Registry 24
3.5 Project Directory Structure 25
3.6 Using Third-Party Libraries 25
3.6.1 Third-Party Libraries for One Project 26
3.6.2 Third-Party Libraries for All Projects 26
3.7 Configuring KToolbar 26
3.7.1 Setting the Application Directory 27
3.7.2 Setting the javac Encoding Property 27
3.7.3 Working with Revision Control Systems 27
5. Monitoring Applications 39
5.1 Using the Profiler 39
5.1.1 The Call Graph 41
5.1.2 Execution Time and Number of Calls 41
5.1.3 Saving and Loading Profiler Information 41
5.2 Using the Memory Monitor 42
5.2.1 Saving and Loading Memory Monitor Information 44
5.3 Using the Network Monitor 44
Contents v
8.4 Well-Behaved MIDlets 66
A. Application Demonstrations 79
A.1 Overview 79
A.2 General Instructions 81
A.3 BluetoothDemo 82
A.4 Demo3D 83
A.4.1 Life3D 83
A.4.2 PogoRoo 84
A.4.3 retainedmode 85
A.5 JSR172Demo 86
A.6 mmademo 86
C. Internationalization 115
C.1 Locale Setting 115
C.2 Emulated Locale 116
C.3 Character Encodings 116
C.3.1 Java Compiler Encoding Setting 117
Contents vii
C.4 Font Support in the Default Emulator 117
Index 119
This document describes how to work with the J2ME Wireless Toolkit.
If you need help getting started with Java programming, try the New to Java Center:
http://java.sun.com/learning/new2java/
For a quick start with MIDP programming, read Learning Path: Getting Started with
MIDP 2.0:
http://developers.sun.com/techtopics/mobility/learn/midp/
midp20/
Related Documentation
This book is not a tutorial in MIDP programming, nor is it a tutorial in
programming any of the additional APIs that are supported by the toolkit. This
section lists related specifications. Although specifications are definitive, they are
not always the most accessible kind of information. For a variety of developer-
centered articles, try Sun’s mobility web site:
Preface ix
http://developers.sun.com/techtopics/mobility/
Topic Title
Customizing the J2ME Wireless Toolkit J2ME Wireless Toolkit Basic Customization Guide
Release Notes J2ME Wireless Toolkit Release Notes
MIDP 1.0 - JSR 37 Mobile Information Device Profile for the J2ME™
Platform
MIDP 2.0 - JSR 118 Mobile Information Device Profile 2.0
CLDC 1.0 - JSR 30 J2ME Connected Limited Device Configuration
CLDC 1.1 - JSR 139 J2ME Connected Limited Device Configuration
WMA 2.0 - JSR 205 Wireless Messaging API (WMA)
MMAPI - JSR 135 Mobile Media API
JTWI - JSR 185 Java Technology for the Wireless Industry
J2ME Web Services JSR 172 J2ME Web Services Specification
PDAP Optional Packages - JSR 75 PDA Optional Packages for the J2ME Platform
Bluetooth and OBEX - JSR 82 Java APIs for Bluetooth
Mobile 3D Graphics - JSR 184 Mobile 3D Graphics API for J2ME
Chapter 1 introduces the J2ME Wireless Toolkit and the development features it
provides.
Chapter 3 explains how to work with projects in KToolbar. You’ll learn how to
adjust project properties, manipulate MIDlets, work with the push registry, and
understand the project directory structure.
Chapter 4 describes the emulator and explains how to adjust its options and take
advantage of its many features.
Chapter 5 shows how you can examine the performance of your application
using the method profiler, memory monitor, and network monitor.
Chapter 6 describes how to sign MIDlet suites and manage keys and certificates.
Chapter 8 explains how the J2ME Wireless Toolkit supports the Mobile Media
API.
Chapter 10 describes how the toolkit implements access to local files and
personal information like contacts and calendar appointments.
Appendix B explains how to use the functionality of the J2ME Wireless Toolkit
from the command line.
Preface xi
Typographic Conventions
http://developer.sun.com/
http://java.sun.com/docs/
Introduction
The J2ME Wireless Toolkit is a set of tools that makes it possible to create
applications for mobile phones and other wireless devices. Although it is based on
the Mobile Information Device Profile (MIDP) 2.0, the J2ME Wireless Toolkit also
supports a handful of optional packages, making it a widely capable development
toolkit.
1. Depending on how Windows is configured, you might need to choose Start > All Programs instead of Start
> Programs.
1
FIGURE 1 The KToolbar window
Once the application is open, all you need to do is press the Run button. The
emulator will pop up running the example application.
All the source code for the demonstration applications is available in the
{toolkit}\apps directory. Each demonstration has its own project directory. Inside
the project directory, the source files are in the src directory. For example, the
source code for the games demonstration is in {toolkit}\apps\games\src
directory.
The only additional tool you need is a text editor for editing source code.
JSR Name
API URL
Chapter 1 Introduction 3
TABLE 1 Supported JCP APIs in the J2ME Wireless Toolkit
JSR Name
API URL
This chapter describes how you can use the J2ME Wireless Toolkit to create
applications. It begins with a description of toolkit projects, then works through the
development process.
There are two basic development cycles you are likely to follow in creating MIDlet
suite applications. The first is quicker and simpler; you will probably use it in your
initial development. The second cycle is longer but allows for more comprehensive
and realistic testing.
Toward the end of the chapter you’ll read about how to use the J2ME Wireless
Toolkit with advanced development tools like an obfuscator and a debugger. A
final section briefly describes how to configure a web server to serve MIDP
applications.
The J2ME Wireless Toolkit works on one project at a time. You can create a new
project or open an existing project.
In this chapter you will work with a very simple example project. As you read
about each step in the development cycles, you can work along in the toolkit.
To create a new project, first start KToolbar. On Windows, choose Start > Programs
> J2ME Wireless Toolkit 2.2 > KToolbar.2 You’ll see the KToolbar window.
2. Depending on how Windows is configured, you might need to choose Start > All Programs instead of Start
> Programs.
5
FIGURE 2 The KToolbar window
Click on New Project... The toolkit will ask you for the name of the project and the
name of the MIDlet class you will write. Fill in the names and click Create Project.
The project options automatically pop up, allowing you to set up the build
environment for the project. The default options are fine for this example; just click
on OK to dismiss the window. In the KToolbar console, you’ll see some messages
telling you exactly where to store the source code and resource files for this project.
1. Edit source code. In this step, you create Java source files and resource files that
will be used by your application.
2. Build. The J2ME Wireless Toolkit compiles and preverifies your Java source files.
3. Run. The compiled Java class files are run on the emulator.
If an error occurs when the toolkit attempts to compile your source files, go back
and edit them again. If you find a bug when you are testing your application in the
emulator, edit the source files to fix the bug.
Now that you understand the simple development cycle at a high level, the rest of
this section illustrates how you can accomplish each step using the J2ME Wireless
Toolkit.
display.setCurrent(mainForm);
}
2.2.2 Build
The next step is to build your source code. The toolkit makes this part very easy.
In the KToolbar window, click on the Build button. Assuming you saved your
source file in the right place, the toolkit will find it and compile it. Compilation
errors are displayed in the KToolbar console. If you have errors, go back and edit
the source code to fix them. Once you’ve eliminated your errors, the KToolbar
console tells you the project was successfully built.
Behind the scenes, the J2ME Wireless Toolkit also preverifies the compiled class
files. MIDlet class files must be preverified before they can be run on a MIDP
device or emulator. The toolkit quietly handles this detail for you; you probably
won’t ever realize it’s happening. See the CLDC specification for more information
on preverification.
2.2.3 Run
Once the project builds successfully, you are ready to try it out in the emulator.
Click on the Run button. The emulator pops up and shows a list of all the MIDlets
in your project.
Choose the MIDlet you want and select Launch. If you’re following along with the
TinyMIDlet example, you’ll see the fruit of your labors:
2. Package. In this step, the J2ME Wireless Toolkit compiles and preverifies the
source files (essentially the same as the Build step from before). Then it bundles
the Java class files and resource files into a MIDlet suite JAR file and a MIDlet
suite descriptor.
3. Install. MIDlet suites need to be installed before they can be run. You can install
the MIDlet suite into the J2ME Wireless Toolkit emulator or a real device.
4. Run. As in the simple development cycle, run your application and test for
bugs.
In the full development cycle, the first step is identical to the simple development
cycle. Editing source code is the same as always. The Build step is now
incorporated in packaging.
The full development cycle includes two new steps, packaging and installing.
Finally, running an installed application is different in important ways from
running an application in the simple development cycle.
2.3.1 Package
The J2ME Wireless Toolkit automates the task of packaging a MIDlet suite. The end
result of packaging is two files, a MIDlet descriptor and a MIDlet suite JAR. The
descriptor is a small text file that contains information about the MIDlet suite. The
JAR contains the class files and resources that make up the MIDlet suite. Devices
can use the descriptor to learn about the application before downloading the entire
JAR, an important consideration in a memory-lean, bandwidth-starved wireless
world.
To ask the toolkit to package your MIDlet suite, choose Project > Package > Create
Package from the KToolbar menu. The MIDlet suite descriptor and JAR are
generated and placed in the bin directory of your project.
Packaging might involve additional steps. You can use a code obfuscator to shrink
the size of the MIDlet suite JAR, a technique that is described later in this chapter.
In addition, the J2ME Wireless Toolkit provides tools to allow you to
cryptographically sign MIDlet suites. See Chapter 6, “Security and MIDlet
Signing,” for more information.
The emulator also has the capability of installing applications into its memory in a
process that resembles how applications are transmitted and installed on real
devices. To install applications in the J2ME Wireless Toolkit emulator, choose
Project > Run via OTA.
The emulator window pops open, but instead of running your MIDlet classes
directly, this time the emulator shows the welcome screen of its Application
Management Software (AMS). The emulator’s AMS is an example of the type of
software that real devices must have to manage MIDlet suites.
Choose Go from the menu to begin the installation. The emulator shows a list of
the applications it finds at the URL. Choose the only one and select Install from the
menu. The emulator gives you one last chance to confirm your intentions.
Choose Install again to finish the installation. You’ll be returned to the emulator’s
installed list of applications, which now includes the application you just installed.
Run via OTA is an extremely useful mechanism that makes it easy to install your
MIDlet suite on the toolkit emulator. Some features must be tested using this
technique, including the push registry and the installation of signed MIDlet suites.
If you want to test your MIDlet suite on a real device, you’ll need to install it first.
How this happens depends heavily on the device you are using. There are two
likely possibilities:
■ You can deploy the application on a web server, then transmit the application
from server to device using the Over the Air (OTA) protocol described in the
MIDP 2.0 specification. This is most likely the same mechanism that users will
encounter when they go to purchase or install your application.
■ You might be able to transfer the MIDlet suite to the device using a Bluetooth,
infrared, or serial connection. This is quite a bit simpler than running a web
server, and although it won’t give you any insights into the process of installing
your application on the device via OTA, it allows you to see how your
application performs on the device.
2.3.3 Run
Once the application is installed, running it is simple. Just choose the application
from the list and choose Launch from the menu.
You can use an obfuscator in the packaging step of the development cycle.
Although the J2ME Wireless Toolkit doesn’t come with an obfuscator, it is already
configured to use the ProGuard obfuscator. All you need to do is download
ProGuard and put it in a place where the toolkit can find it.
ProGuard is published under the terms of the GNU General Public License (GPL).
If you are comfortable with the terms of the license, you can download and use
ProGuard free of charge.
Once ProGuard is installed, you can use it by choosing Project > Package > Create
Obfuscated Package.
In some cases you will need to provide a script file that controls how the obfuscator
works. If you are loading classes using Class.forName(), for example, you need
to tell ProGuard to leave the class names unchanged.
Create a script file using a text editor, then save it under the project’s main
directory. Consult the ProGuard documentation for information on script files.
Next you need to tell the toolkit how to find this file. To do this, edit
{toolkit}\wtklib\{platform}\ktools.properties, where {platform} is the name of
your underlying platform (most likely Windows or Linux). Add a line as follows:
obfuscate.script.name: scriptfile
Replace “scriptfile” with the name you used for the script file. You will need to quit
and restart KToolbar for the change to take effect.
The J2ME Wireless Toolkit also includes support for RetroGuard. If you want to use
RetroGuard, you’ll need to download it separately and change the toolkit’s
configuration.
3. Extract the retroguard.jar file from downloaded zip file to the bin directory
of your J2ME Wireless Toolkit installation.
You will need to supply your own debugger. You can use the jdb debugger from
J2SE™ or another debugger of your choice.
Begin by choosing Project > Debug from the KToolbar menu. Enter the TCP/IP
port number that the debugger will use to connect to the emulator. Click on
Debug. The emulator begins running and waits for a connection from a debugger.
Start up your debugger and attach it to the port you specified. Make sure to set the
remote debugger to run in remote mode and to use TCP/IP. For more information,
consult the debugger’s documentation.
Information about using jdb with the J2ME Wireless Toolkit is here:
Debugging MIDlets
http://developers.sun.com/techtopics/mobility/midp/questions/
jdb/
1. Change the JAD file’s MIDlet-Jar-URL property to the URL of the JAR file. The
URL should be an absolute path. For example:
MIDlet-Jar-URL: http://your.server.com/midlets/example.jar
2. Ensure that the Web server uses the correct MIME types for JAD and JAR files:
a. For MIDlet suite descriptors, map the .jad extension to the text/
vnd.sun.j2me.app-descriptor MIME type.
b. For MIDlet suite JARs, map the .jar extension to the application/java-
archive MIME type.
The emulator implements the device behavior during OTA provisioning. You can
use the emulator to test and demonstrate the full provisioning process of MIDlet
suites from a server to the device. All you need to do is launch the emulator’s
AMS. (You may already be familiar with the AMS if you have used KToolbar’s Run
via OTA option.
{toolkit}\bin\emulator -Xjam
Now follow the AMS prompts to install your application. This process is very
similar to the Run via OTA option described earlier in this chapter, except you will
need to enter the URL of your own server to install your application.
In the last chapter, you learned how the J2ME Wireless Toolkit helps you with the
MIDP development cycle. This chapter delves more deeply into the details of
working with projects, including the following:
■ Selecting the target APIs for a project
■ Manipulating MIDlet suite attributes, including the list of MIDlets
■ Understanding the project directory structure
■ Including third-party libraries in a project
For example, even though the toolkit supports JSR 184, the Mobile 3D Graphics
API, you might want to develop applications that don’t make use of that API. The
project’s API Selection settings make it possible to choose only the APIs you want
to use.
To see how this works, launch KToolbar and open a project. Then click on
Settings... to bring up the following window:
19
FIGURE 13 The project settings window
On the API Selection tab, the Target Platform setting controls the appearance of
the rest of the tab. Choose the setting that best suits your need, and tweak your
selection with the controls below. For example, if you’re developing applications
for JTWI-compliant devices, choose JTWI from the combo box. Then use the
controls below to specify which version of CLDC you want to use and whether
MMAPI should be present.
The toolkit applies your selections when you compile your source code.
Note – API selections do not apply to the emulator. The emulator always supports
all the available APIs. The API selections you make in the project settings apply
only to building a project. In essence, the API selections choose which classpath the
toolkit uses for compiling and preverifying your source files.
To see the attributes, run KToolbar and open a project. Then click on Settings....
The three tabs that define attributes are Required, Optional, and User Defined.
Consult the MIDP 2.0 specification for the definitions of the required and optional
attributes. The J2ME Wireless Toolkit takes care of most of the details. In the early
stages of development, you might not have to worry about the attributes at all.
Once your application is stable and you’re starting to think about deploying on real
devices and going to market, you should come back and adjust the values.
To adjust a value on the Required or Optional tabs, click on the cell next to the
attribute key you wish to change. Type in the new value.
To create new user-defined attributes, click on the User Defined tab. Press Add and
fill in the key name. You can then edit the attribute value by clicking in the value
column next to the key, just as you would with required or optional attributes.
Select an attribute and click on Remove if you wish to remove the key and value
entirely.
To add a new MIDlet, click on Add. Fill in the name, icon file name, and class
name. You can leave the icon file name blank if you wish. To change values or
remove MIDlet entries, use the Edit and Remove buttons.
To add an entry to the push registry, press Add and fill in values for the connection
URL, MIDlet class, and allowed sender. To edit an entry, select the entry and press
the Edit button. To remove a push registry entry, select it and press Remove.
Directory Description
bin The MIDlet suite descriptor and JAR are placed in this directory
when you package the project. This directory also contains the
unpackaged manifest information and might include an HTML file
that is used internally when you do Run via OTA.
classes This directory is used by the toolkit to store compiled class files.
lib Place a third-party library in this directory to include it in this
project.
res Images, sounds, and other resource files go in this directory. They
are packaged into the root of the MIDlet suite JAR.
src Place source files in this directory.
tmpclasses This directory is used by the toolkit.
tmpsrc This directory is used by the toolkit.
If you want to remove temporary directories and files from the project, choose
Project > Clean from the KToolbar menu.
For example, if you installed the J2ME Wireless Toolkit in C:\WTK22 and your
application is called Tiny, the class library would go in
C:\WTK22\apps\Tiny\lib. When you build, run, debug, and package your
project, the class files in the lib directory are used.
For example, to set the application directory to D:\dev\midlets, you would use:
kvem.apps.dir: D:\\dev\\midlets
As a result, you prevent KToolbar from treating revision control files as source and
resource files. For example, KToolbar would treat a file named
src\SCCS\s.MyClass.java as being an SCCS revision control file and not a Java
source file.
The J2ME Wireless Toolkit emulator simulates a MIDP device on your desktop
computer. It is a convenient way to see how your application performs in a MIDP
environment and gives you a tight development cycle that is entirely contained on
your desktop computer.
The emulator does not represent a specific device, but it provides correct
implementations of its supported APIs.
You can create your own emulator skins if you wish. See the Basic Customization
Guide for details.
29
4.2 Using the Emulator
The emulator looks and acts like a mobile phone. In this section you’ll learn how to
control the emulator. Although the description and figures are based on the
DefaultColorPhone skin, all the skins operate in a similar way.
Entering text works much as it does on many real devices. Press a number key
multiple times to get the letter you want. For example, press the 5 key twice for the
letter K. When you are entering text, the asterisk key (*) switches between upper
case, lower case, numbers, and symbols. The indicator at the top of the screen
shows your current mode. The pound key (#) enters a space.
Alternately, you can just type on your keyboard to enter text. Although this is
convenient for entering text, you must remember that it is a convenience your
users will most likely be lacking.
If your development computer is behind a firewall, you might use a proxy server to
make HTTP connections. If you’re not sure, try examining your browser’s settings
to see if it uses proxy servers.
If you are using proxy servers, you need to configure the emulator to use the same
proxy servers. To do this, choose Edit > Preferences.... On the Network
Configuration tab, fill in the names and port numbers for the proxy server you
wish to use. You can also select which version of HTTP you wish to use.
Note – If multiple instances of the same emulator skin run simultaneously, the
J2ME Wireless Toolkit will generate unique file paths for each one. For example, a
second instance of DefaultColorPhone might have a file path name of
{toolkit}\appdb\DefaultColorPhone.1089982856218.
To adjust the persistent storage settings, choose Edit > Preferences... and click on
the Storage tab. Enter the name of the directory you wish to use for persistent
storage. You can only enter a relative path, and the directory you specify is created
in the {toolkit}\appdb directory.
If you wish, you can enter a limit in kilobytes for the size of the persistent storage.
Bear in mind that the storage implementation has some overhead in addition to the
space your application uses. For example, if you enter 8 kB for the persistent
storage size, 8192 bytes is available for both your application data and the storage
overhead.
If you wish to erase the persistent storage of the emulator, choose File > Utilities...
from the KToolbar menu. Click on the Clean Database button to wipe the
persistent storage clean.
The J2ME Wireless Toolkit allows you to simulate the constrained environment of a
real device. Although the emulator does not represent a real device, adjusting the
performance settings gives you useful information about how your application
performs under varying runtime conditions.
Adjust the Graphics primitives latency to have an effect on the amount of time
that elapses between your application’s calls to drawing methods in the Graphics
class and when the drawing actually takes place.
To change the screen characteristics, choose one of the Display refresh types. If
you choose a Periodic type, you will also need to specify the Refresh Rate.
To simulate the slower speed of a real device, check Enable VM speed emulation
and choose the speed you want.
You can adjust the simulated network speed by checking Enable network
throughput emulation and choosing a speed.
The emulator provides a simple mechanism to pause and resume running MIDlets.
This is very helpful for testing your application’s behavior when it is paused.
To resume the MIDlet’s operation, choose MIDlet > Resume from the menu.
To run the emulator’s Application Management Software (AMS), choose the OTA
Provisioning item, which is roughly analagous to KToolbar’s Run via OTA feature.
The emulator pops up with the AMS welcome screen, and you can install
applications by typing in a URL.
To change the emulator’s preferences, choose the Preferences item from the toolkit
program group. This pulls up the same preferences window as choosing Edit >
Preferences... from the KToolbar menu.
The J2ME Wireless Toolkit utilities are also accessible without running KToolbar.
Just choose the Utilities item.
Finally, you can change which emulator skin is used by default. Choose the
Default Device Selection item, and choose one of the available emulator skins.
Next time you launch the emulator the selected skin is used.
You can also run the emulator from a command prompt. See Appendix B,
“Command Line Reference,” for more information.
http://developers.sun.com/techtopics/mobility/midp/articles/
emulators/
Monitoring Applications
The J2ME Wireless Toolkit provides several tools to monitor the behavior of your
applications. These tools are helpful in debugging and optimizing your code.
■ The profiler lists the frequency of use and execution time for every method in
your application.
■ The memory monitor shows the usage of memory while your application runs.
■ The network monitor shows network data transmitted and received by your
application. It supports many network protocols including HTTP, HTTPS, SMS,
and CBS.
■ Tracing outputs low-level information to the KToolbar console.
Note – Monitoring features might slow down the execution of your application.
To turn on the profiler, choose Edit > Preferences... from the KToolbar menu. Click
on the Monitor tab. If you are interested in seeing profiling information for all the
system implementation methods, check Show System Classes. Otherwise, the
profiler shows only system methods that contain calls to your application methods.
39
FIGURE 20 Turning on the profiler
Now run your application by clicking on the Run button. Interact with your
application as you normally would. When you’re finished, shut down the emulator.
The profiler pops up with information about all the method calls in your
application.
Note – The profiling values obtained from the emulator do not reflect actual
values on a real device.
You can search for a particular class or method name. Click on Find... and fill in a
name. The search is performed from the current selection in the call graph to the
end. If you want to search the entire call graph, check Wrap before you click on the
Find button.
As you click on different nodes in the call graph, the right side of the profiler
shows details about the methods for that node.
Click on any column to sort by that column. Click a second time to switch the sort
between ascending and descending.
The right pane shows the methods contained in the currently selected node in the
call graph. If you want to see every method, click on the <root> node in the call
graph.
To load a profiler session, choose File > Utilities... from the KToolbar menu. Click
on Open Session in the Profiler box. When you select a file, the profiler window
appears with all the session information.
To turn on the memory monitor, choose Edit > Preferences... from the KToolbar
menu. Click on the Monitor tab. Check Enable Memory Monitor.
Next time you run the emulator, the memory monitor window pops up, displaying
a graph of your application’s memory usage over time. The memory monitor slows
down your application startup because every object created is recorded.
Remember, you can modify the heap size using the Storage tab of the KToolbar
preferences. See Chapter 3, “Working With Projects,” for details.
To request the system to perform a garbage collection, click on Run GC.
Note – The memory usage you observe with the emulator is not going to be
exactly the same as memory usage on a real device. Remember, the emulator does
not represent a real device. It is just one possible implementation of its supported
APIs.
To see details about the objects in your application, click on the Objects tab in the
memory monitor window.
You can search for a specific class name by choosing View > Find... from the
memory monitor window menu.
To load a memory monitor session, choose File > Utilities... from the KToolbar
menu. Click on Open Session in the Memory Monitor box. When you select a file,
the memory monitor window appears with all the session information.
To turn on the network monitor, choose Edit > Preferences... from the KToolbar
menu. Click on the Monitor tab. Check Enable Network Monitoring.
Next time you run the emulator, the network monitor window pops up.
When your application makes any type of network connection, information about
the connection is captured and displayed. The figure shows two HTTP requests
and responses.
The display on the left side shows a hierarchy of messages and message pieces.
Click on a message or a portion of a message to see details in the right side of the
network monitor.
Message bodies are shown as raw hexadecimal values and the equivalent text.
Note – You can examine messages that are still in the process of being sent.
Incomplete messages are indicated by bold highlighting in the message tree.
HTTP/HTTPS Enter text to match the various parts of HTTP messages: URL,
status line, headers, or body. For example, entering “slashdot” in
the URL field would filter to show only messages whose URL
contained “slashdot”.
SMS/CBS You can specify a protocol, message type, and direction to match.
Furthermore, you can enter text to match in the sender, receiver,
and message content.
MMS Enter text to match the direction, sender, receiver, and copied (cc)
and blind copied (bcc) receivers. In addition, you can filter on the
subject, content ID, content location, MIME type, and encoding.
OBEX/SPP/L2CAP You can filter using the URL or header content.
Socket/SSL/ Enter text to match in either the connection string (URL) or content.
Datagram/Comm
When you are done entering filter settings, press OK to return to the network
monitor. The Filter checkbox is checked, indicating that a filter is in use. To disable
the filter and see all messages, uncheck the checkbox.
Sorting parameters are dependent on the message protocol you choose. For
instance, sorting by time is not relevant for socket messages.
For definitive information, consult the MIDP 2.0 specification. For an overview of
MIDlet signing using the J2ME Wireless Toolkit, read this article:
http://developers.sun.com/techtopics/mobility/midp/articles/
permissions/
If you need more background on public key cryptography, try this article:
http://developers.sun.com/techtopics/mobility/midp/articles/
security1/
This chapter describes support for protection domains, permissions, and MIDlet
signing in the J2ME Wireless Toolkit.
6.1 Permissions
MIDlets must have permission to perform sensitive operations, like connecting to
the network. Permissions have specific names, and MIDlet suites can indicate their
need for certain kinds of permissions through attributes in the MIDlet suite
descriptor.
49
In the J2ME Wireless Toolkit, you can add these permission attributes to a project
by clicking on the Settings... button in KToolbar. Select the Permissions tab. The
MIDlet-Permissions box shows permissions which the MIDlet must possess, while
the MIDlet-Permissions-Opt box contains permissions that the MIDlet would like
to have but does not need absolutley.
To add a permission to either box, click on Add and choose the permission you
want to add. To remove a permission, highlight it and click on Remove.
When you press the Run button to run your application in the emulator, your code
runs in the untrusted protection domain by default. You can change which
protection domain is used by choosing Edit > Preferences... from the KToolbar
menu. Select the Security tab. You can now choose the default protection domain
from the combo box.
Things are different when you use Run via OTA. Your packaged MIDlet suite is
installed directly into the emulator, and it is placed in a protection domain at
installation time. The emulator uses public key cryptography to determine the
protection domain of installed MIDlet suites.
If the MIDlet suite is not signed, it is placed in the untrusted domain. If the
MIDlet is signed, it is placed in whatever protection domain is associated with the
root certificate of the signing key’s certificate chain.
The J2ME Wireless Toolkit provides tools to sign MIDlet suites, manage keys, and
manage root certificates.
Signing is very easy. Just select the key you want to use in the Alias List and click
on the Sign MIDlet Suite... button.
After you click on Create, the toolkit prompts you to choose a protection domain.
The connection between the key pair you just created and a protection domain
might seem oblique, but it makes perfect sense:
■ The toolkit creates a self-signed root certficate using the key pair you just
created.
■ The root certificate is added to the emulator’s list of root certificates.
■ The toolkit needs to associate the root certificate with a protection domain.
Now imagine what happens when you install a MIDlet suite signed with your new
key:
■ The implementation examines the certificate chain in the MIDlet suite descriptor.
In this case the certificate chain is a single certificate, the self-signed root.
■ The implementation tries to find the root of the certificate chain in its internal
list. This succeeds because the root certificate was added when you create the
key pair.
■ The implementation considers the certificate valid and uses it to verify the
signature on the MIDlet suite.
■ The MIDlet suite is installed into whatever protection domain you picked.
1. Generate a new key pair. In the J2ME Wireless Toolkit you can do this by
pressing New Key Pair... in the MIDlet signing window, as described above.
3. Send the CSR to a certificate authority (CA). The CA will need more information
from you to verify your identity. You will also need to pay the CA for the
certificate they generate for you.
4. Once the CA has verified your identity and taken your money, you will receive
a certificate from the CA that certifies your public key.
5. Import the certificate into the J2ME Wireless Toolkit by pressing Import
Certificate... in the MIDlet signing window.
You can now use your own private key to sign MIDlet suites. The J2ME Wireless
Toolkit will take care of the details of placing the signature and your certificate into
the MIDlet suite.
Choose File > Utilities... from the KToolbar menu. Click on the Manage
Certificates button to open up the certificate manager window.
Each certificate is shown as a single line in the left part of the window, the
Certificate List. When you click on a certificate, its details are shown in the right
part of the window. You’ll also see the certificate’s associated protection domain.
To import a certificate from a J2SE keystore, choose Action > Import J2SE
Certificate from the menu in the certificate manager window. First, choose a
protection domain for the certificate. Then select the keystore file and enter the
keystore password. Finally, select the alias for the certificate you wish to import.
The J2ME Wireless Toolkit supports the Wireless Messaging API (WMA) with a
sophisticated simulation environment. WMA 1.1 (JSR 120) enables MIDlets to send
and receive Short Message Service (SMS) or Cell Broadcast Service (CBS) messages.
WMA 2.0 (JSR 205) includes support for MMS messages as well.
This chapter describes the tools you can use to develop WMA applications. It
begins by showing how to configure the emulator’s support of WMA. Next, you’ll
learn about the WMA console, a handy utility for testing WMA applications. The
chapter concludes with a brief description of the network monitor’s WMA support.
You can affect the assigned phone numbers by choosing Edit > Preferences... from
the KToolbar menu and clicking on the WMA tab.
57
FIGURE 29 Setting WMA preferences
The Phone Number of Next Emulator field is just what it sounds like. If you fill in
a number for this field, the next emulator instance will have that number.
If the Phone Number of Next Emulator is already in use, or if the field is blank,
then the First Assigned Phone Number is used for the next emulator instance.
Subsequent instances count up.
For example, suppose you fill in +6269333 for the Phone Number of Next
Emulator and +5550000 for the First Assigned Phone Number. If you launch four
emulator instances, their numbers will be +6269333, +5550000, +5550001, and
+5550002.
If you’d like the toolkit to lose some message fragments, adjust the Random
Message Fragment Loss slider to the desired percentage. If you would like to
simulate a delay between the time message fragments are sent and received, enter
the delay in milliseconds in the Message Fragment Delivery Delay field.
To launch the WMA console, choose File > Utilities... from the KToolbar menu.
Click on Open Console in the WMA box.
The window automatically lists the phone numbers of all running emulator
instances. Select a destination (Control-click to select multiple destinations) and
enter a port number if you wish. Type your message and click Send.
Selecting recipients is the same as for sending text SMS messages. You can type in
the path of a file directly, or click on Browse... to open up a file chooser.
The window for composing MMS messages has two tabs, one for recipients and
one for content. Begin by filling in a subject and recipient. If you wish to add more
recipients, click on the Add button. For example, to send a message to a running
emulator whose number is +5550001, you would fill in the To line as mms://
+5550001. To remove a recipient, first select its line, then click on Remove.
To add media files to the message, click on the Parts tab. Click on Add to add a
part to the message. To remove a part, select it and press Remove.
Click on the SMS/CBS or MMS tabs to see WMA messages. Information about the
messages and their fragments is shown in the left pane of the network monitor.
Click on a message or message fragment to see its details in the right pane.
The Mobile Media API (MMAPI) provides a standard API for rendering and
capturing time-based media, like audio or video. The API was designed to be
flexible with respect to the media formats, protocols, and features supported by
various devices.
65
8.2 Using MediaControlSkin
The J2ME Wireless Toolkit comes with an emulator skin, MediaControlSkin, that
is focused on multimedia playback and control. The skin includes buttons with
symbols representing play, stop, volume up and volume down, and other
commands. To see the usefulness of MediaControlSkin, try it out with the
mmademo demonstration application.
See the mmademo example application for details and source code that
demonstrates how to capture audio and video.
The J2ME Wireless Toolkit will print a message to the console if you pause a
MIDlet and it does not stop its running Players. You can test this feature yourself
using the PausingVideoTest MIDlet in the mmademo demonstration application.
See Appendix for details.
The warning message is printed once only for each running emulator.
http://jcp.org/en/jsr/detail?id=184
JSR 184 provides a standard API for CLDC/MIDP devices, enabling a new
generation of 3D applications. The immediate mode API, in turn, is compatible
with OpenGL ES, a standard lightweight API for 3D graphics. See http://
khronos.org/ for more information on OpenGL ES.
67
For an example of immediate mode, see the Life3D MIDlet in the Demo3D
example application.
For an example of retained mode, see the retainedmode MIDlet in the Demo3D
example application.
In general, however, the best way to improve the rendering speed of 3D scenes is to
make some compromises in quality. The Mobile 3D Graphics API includes
rendering hints so that applications can suggest how the implementation can
compromise quality to improve rendering speed.
Several vendors offer tools for authoring content and converting files to the JSR 184
format. Superscape (http://superscape.com/) is one such vendor.
The J2ME Wireless Toolkit supports JSR 75, the PDA Optional Packages for the
J2ME Platform. JSR 75 includes two independent APIs:
■ The FileConnection optional package allows MIDlets access to a local device
file system.
■ The Personal Information Management (PIM) optional package includes APIs
for manipulating contact lists (address book), calendars, and to-do lists.
This chapter describes how the J2ME Wireless Toolkit implements the
FileConnection and PIM APIs.
In the J2ME Wireless Toolkit emulator, the FileConnection API allows MIDlets
to access files stored on your desktop computer’s hard disk.
The files that can be accessed using FileConnection are stored in subdirectories
of {toolkit}\appdb\{skin}\filesystem. For example, the DefaultColorPhone
emulator skin comes with a root directory installed called root1, which contains a
file called Readme. The full path of the file is
{toolkit}\appdb\DefaultColorPhone\filesystem\root1\Readme.
Note – If multiple instances of the same emulator skin run simultaneously, the
J2ME Wireless Toolkit will generate unique file paths for each one. For example, a
second instance of DefaultColorPhone might have a file system path name of
{toolkit}\appdb\DefaultColorPhone.1089982856218\filesystem.
71
Each subdirectory of filesystem is called a root. The J2ME Wireless Toolkit
provides a mechanism for managing roots. While the emualtor is running, choose
MIDlet > External events from the emulator window’s menu. You’ll see a utility
window for adding and removing roots.
The mounted roots and their contents are available to applications using the
FileConnection API.
To add a new root directory, click on Mount New... and fill in a name for the
directory. To make a directory inaccessible to the FileConnection API, select it in
the list and click Unmount.
Inside the list directory, items are stored in vCard or vCalendar format (see http:/
/www.imc.org/pdi/). Contacts are stored in vCard format, while calendar and
to-do items are both stored in vCalendar format.
The J2ME Wireless Toolkit emulator supports JSR 82, the Java APIs for Bluetooth.
JSR 82 includes two independent APIs:
■ The Bluetooth API provides an interface to Bluetooth wireless networking,
including device discovery and data exchange.
■ The OBEX API allows applications to use the Object Exchange (OBEX) protocol
over Bluetooth or other communication channels.
This chapter describes how the J2ME Wireless Toolkit implements the Bluetooth
and OBEX APIs.
73
11.3 Setting OBEX and Bluetooth Preferences
The J2ME Wireless Toolkit allows you to configure the Bluetooth and OBEX
simulation environment. Choose Edit > Preferences... from the KToolbar menu to
see the following window.
At the API level, the discovery timeout value determines how long a call to
Connector.open("irdaobex://discover...") will block before it returns or
throws an exception.
The maximum packet length affects how much data is sent in each packet between
emulators. Shorter packet values will result in more packets and more packet
overhead.
Property Description
The J2ME Wireless Toolkit emulator supports JSR 172, the J2ME Web Services
Specification. JSR 172 provides APIs for accessing web services from J2ME
applications. It also includes an API for parsing XML documents.
The J2ME Wireless Toolkit provides a stub generator that automates creating source
code for accessing web services. To get to the stub generator, choose File >
Utilities... from the KToolbar menu. Click on Stub Generator.
The WSDL Filename or URL should point to the WSDL file for the web service
you want to access. The Output Path indicates the location where you want the
stub files to be placed. Output Package indicates the Java language package name
for the stub files. Finally, choose whether you want to generate CLDC 1.0 or CLDC
1.1 stubs.
77
78 J2ME Wireless Toolkit User’s Guide • October 2004
APPENDIX A
Application Demonstrations
This appendix describes the application demonstrations that are bundled with the
J2ME Wireless Toolkit.
A.1 Overview
The J2ME Wireless Toolkit includes demonstration applications that highlight some
of the technologies and APIs that are supported by the emulator.
The following table lists all the demonstration applications that are included in this
release. The demonstrations that are new or enhanced in this release are marked
with NEW.
The goal of these demonstrations is to give you a glimpse of the API features of the
emulator and the enhancements throughout the toolkit.
Most demonstration applications are simple to run. The next section contains
instructions for running most demonstrations. Demonstrations that have additional
documentation are linked in the table below.
79
\WTK22, the source code for the SMS sender MIDlet (example.sms.SMSSend) in
WMADemo is contained in
\WTK22\apps\WMADemo\src\example\sms\SMSSend.java.
Special
Demonstration APIs Description Instructions
NEW PDAPDemo JSR 75 PIM and Shows how to manipulate Section A.8
FileConnection contacts, calendar items, and to-
do items. Demonstrates
accessing local files.
Special
Demonstration APIs Description Instructions
NEW WMADemo WMA 2.0 Shows how to send and receive Section A.9
SMS, and CBS, and MMS
messages
The first step is to run KToolbar. To do this, go to the Windows Start menu and
choose Start > Programs > J2ME Wireless Toolkit 2.2 > KToolbar. The KToolbar
window pops up:
FIGURE 40 KToolbar
Click on the Open Project... button to open a demonstration application. You'll see
a list of all the available applications.
Select one and click on the Open Project button in the dialog.
Once the application is opened, all you need to do is press the Run button. The
device emulator will pop up running the example application. Choose a specific
demonstration to run from the menu and press the soft button for Launch.
Some demonstrations require other setup and instructions. Check the full list to see
if there are specific instructions for a demonstration.
A.3 BluetoothDemo
This application contains a MIDlet that demonstrate the use of JSR 82’s Bluetooth
API.
Bluetooth Demo shows how images can be transferred between devices using
Bluetooth. You will need to run two instances of the emulator to see how this
demonstration works.
In the first emulator, choose Bluetooth Demo, then Server. The emulator will ask
you if you want to allow a Bluetooth connection. Choose Yes. The server starts up
and displays a list of images. At the beginning, none of the images are being made
available on the Bluetooth network. To make images available, select them and
choose Publish image from the menu. Images with a green icon are published,
while those with a purple icon are not.
On the second emulator, choose Bluetooth Demo, then Client. The MIDlet tells
you it’s ready to search for images. Choose Find. The MIDlet will find the other
emulator and get a list of images from it. Select one from the list and choose Load.
The emulator asks if you want to allow the connection. Choose Yes.
In the first emulator, the server, a prompt appears, asking if you want to authorize
the connection from the client. Choose Yes. The image is transferred via simulated
Bluetooth and shown on the client emulator.
You can avoid the permission prompts by running the demonstration in the
trusted protection domain.
A.4 Demo3D
This application contains three MIDlets that show off the emulator's support of JSR
184, the Mobile 3D Graphics API.
A.4.1 Life3D
Life3D implements the popular Game of Life in three dimensions. Live cells are
represented by cubes. Each cell has 26 possible neighbors (including diagonals).
For each step of the animation, cells with fewer than 4 neighbors die of loneliness,
while cells with more than 5 neighbors die of overcrowding. An empty cell with
exactly 4 neighbors will become a new live cell.
The view of the playing board rotates slowly so you can view the board from all
angles.
Button Description
This source code for this example is particularly well-documented. Take a look at
{toolkit}\apps\Demo3D\src\com\superscape\m3g\wtksamples\life3d\Lif
e3D.java.
A.4.2 PogoRoo
PogoRoo shows you the rear end of a kangaroo bouncing up and down on a pogo
stick.
You can get the kangaroo to bounce around the landscape by using the arrow keys.
Push up to go forward, down to go backward, and left and right to change
direction. You might need to hold down the keys to see an effect.
A.4.3 retainedmode
The retainedmode MIDlet plays back a scene file that shows a tireless
skateboarder in an endless loop.
A.5 JSR172Demo
JSR172Demo shows how to access a web service from a MIDlet. The web service is
already running on an Internet server. You should be able to simply build and run
the example.
If you are behind a firewall, you’ll need to configure the emulator’s proxy server
settings. Choose Edit > Preferences... from the KToolbar menu, then select the
Network Preferences tab. Fill in the proxy server addresses and ports.
JSR172Demo contains a single MIDlet, Server Script. Launch it and follow the
prompts. You can browse through simulated news headlines, all of which are
retrieved from the web service.
To see what’s going on behind the scenes, use the network monitor.
A.6 mmademo
The mmademo application contains four MIDlets that showcase the multimedia
capabilities of the J2ME Wireless Toolkit. This section describes the MIDlets and
includes additional information about using multimedia from your applications.
In addition, Simple Player parses ring tones in Ringing Tones text transfer
language (RTTTL). See http://www.convertyourtone.com/rtttl.html for
information on RTTTL.
A key feature of Simple Player is a common set of commands that control media
playback. The commands are available from the Simple Player menu, and some
have associated keypad buttons. The following table describes these commands.
Mute/ 0 Turns off sound but the file continues to play. This command
Unmute toggles to Unmute.
Volume * and Increases or decreases loudness.
#
META Data Displays information provided by the media file such as
copyright information, title, and track list.
Stop in 5 Pauses the audio play in five seconds when set during
seconds playback.
Rate 4 and Alters the rate of speed of playback.
6
Tempo Increases or decreases the tempo of the tone sequence or MIDI
file.
Pitch Up Lowers or raises the notes in a MIDI file.
and
down
Start/Stop Records the audio playback. A file is created containing the
Recording recorded audio in the directory in which the emulator is
running. If you do not specify a filename, a file called
recording.wav is created. This command toggles to Stop
Recording.
Step Frame 7 and Jumps forward or backward one frame at a time in a video file.
9
Play/Stop 2 and Starts or stops the media.
Select
Loop Mode Plays back the audio file immediately after completion of play.
Running Loopmode once plays the audio file once. Pressing a
second time plays the file three times. Pressing a third time
plays the file repeatedly. Pressing a fourth time returns to single
play.
Skip 1 and Skips forward or backward five percent of the duration of the
3 media file. The sound track syncs to the video.
Rewind Returns to the start time of the audio playback.
Stop and 5 Stops plaback and rewinds to the start time.
Rewind
Quick Help Displays a list of commands and keypad buttons.
The commands may or may not be available depending on the media type that
Simple Player is playing. In addition, some commands can be invoked using the
keypad buttons. The following table describes the availability of commands, their
keypad equivalents, and the relevant class from MMAPI.
Note that a short list of commands and the corresponding keypad buttons is
available in the Simple Player application itself. Just choose the Quick Help
command from the menu.
A.6.3 PausingAudioTest
This MIDlet exists to demonstrate how the J2ME Wireless Toolkit will warn you if
a paused MIDlet has not stopped its running Players. After you launch the
MIDlet, choose the Play command to start playing some audio. The screen displays
a status, which is either “Well-behaved” or “Not Well-Behaved.”
Pause the MIDlet by choosing MIDlet > Pause from the emulator window’s menu.
As expected, the MIDlet is paused and no message is displayed on the KToolbar
console. Restart the MIDlet by choosing MIDlet > Resume from the emulator
window’s menu.
Now choose the Misbehave command. Pause the MIDlet again. In the KToolbar
console, you will receive a short lecture about how well-behaved MIDlets release
resources when they are paused.
A.6.4 Video
The Video application illustrates how the emulator is capable of playing animated
GIF files and capturing video. On a real device with a camera, video capture can be
used to show the user what the camera sees.
Attribute Description
PlayerTitle-<n> Name of the nth media title to be played back by the Simple
Player MIDlet.
PlayerURL-<n> Location of the nth media title, PlayerTitle-<n>, to be played
back by the Simple Player MIDlet.
VideoTest-<n> The name of the nth media title to be played back by the Video
application.
VideoTest- Location of the nth media title, VideoTest-<n>, to be played
URL<n> back by the Video application.
A.7 ObexDemo
This application shows how to transfer image files between emulator instances
using the OBEX API. This demonstration shows the use of OBEX over a simulated
infrared connection.
In the second emulator, launch Obex Demo, then choose Send Image. You’ll see a
list of images. Select one and choose Send. The emulator will ask for permission to
make the outgoing connection. Choose Yes.
Back in the first (listening) emulator, you’ll see a prompt asking whether you want
to accept the incoming connection.
Choose Yes. The image you selected is transferred over the simulated infrared link
and displayed on the first emulator.
Now open and run the PDAPDemo project. Launch the FileBrowser MIDlet. You
will see a directory listing. You can browse through the available directories and
files. By default there is one directory, root1.
Select a directory and press the select button to enter it. The root1 directory
contains a single file, Readme.
Using the commands in the demonstration, you can view the file or see its
properties. Try selecting the file and choosing Properties or View from the menu.
In this example application, each type of list works the same way and each list type
contains a single list. For example, if you choose Contact Lists, there is a single
contact list called Contacts. Event Lists contains a single list called Events, and To-
Do Lists conatains a single list called To do.
Once you've selected a list type and chosen the specific list, you'll see all the items
in the list. If this is the first time you've run the example, the list is probably empty.
To add an item, choose New from the menu. The application prompts you for a
Formatted Name for the item. You can add more data fields to this item using Add
Field in the menu. You'll see a list of field names. Pick one, then enter the value for
the new field.
To actually save the list item, choose Commit from the menu.
You can return to the list by choosing the Back command. You'll see the item you
just created in the list.
The items that you create are stored in standard vCard or vCalendar format in the
{toolkit}\appdb\{skin}\pim directory. See Chapter 10 for more information.
The PIM API allows for exporting contact, calender, and to-do items in a standard
format. The exact format depends on the list type. When you are viewing an item
in any list, the menu contains a command for viewing the exported item.
For example, when you are viewing a contact list item, the menu contains Show
vCard. When you choose this command, the exported item is shown on the screen.
Calendar items and to-do items both get exported as vCalendar.
A.9 WMADemo
This application shows how to send and receive SMS, CBS, and MMS messages.
The J2ME Wireless Toolkit offers a flexible emulation environment to support
messaging. Messages can be exchanged between emulator instances and can be
generated or received using the WMA console utility.
Because this example makes use of the push registry, you can't see all of its features
just by using the Run button. You need to use the Run via OTA feature to install
the application into the emulator in a process that mirrors how applications are
installed on real devices. If you don’t know how to do this, read about it in
Chapter 2, “Developing MIDlet Suites.”
Click on the Send SMS... button in the WMA console window. Choose the number
that corresponds to the emulator, probably +5550000. If you're not sure what
number the emulator is using, look in its title bar. Choose the number in the SMS
message window, then fill in a port number of 50000. Then type in your text
message and click on Send.
The emulator will spring to life. First it politely asks if it can launch the WMADemo
application.
Choose Yes. The SMSReceive MIDlet is launched and immediately displays the
incoming SMS message.
You can also use the WMA console to send and receive CBS and MMS messages.
See Chapter 7, “Using the Wireless Messaging API,” for more information.
For example, to send an MMS message from the WMA console to the emulator,
make sure that WMADemo has been installed using Run via OTA as described above.
Leave the emulator running.
In the WMA console, click on Send MMS... to pop up the MMS composition
window. Fill in a message subject, the application ID example.mms.MMSDemo, and
the telephone number of the running emulator.
Next, click on the Parts tab. The WMA console allows you to select files from your
hard disk that you wish to send as parts of the MMS message. Click Add to add a
file to the message. Use the file browser to find the file you want to send and click
OK.
The emulator asks if it can launch WMADemo. Click on Yes. The image and its
information are displayed.
This appendix describes how to operate the J2ME Wireless Toolkit from the
command line and details the steps required to build and run an application. It also
describes the J2ME Wireless Toolkit certificate manager utility, called MEKeyTool,
and the MIDlet signing utility, called JAD Tool (Java Application Descriptor Tool).
B.1 Prerequisites
Before building and running an application from the command line, verify that you
have a version no earlier than 1.4.2 of the J2SE SDK. Run the jar.exe command
(make sure the command is in your PATH) and then run java -version at the
command line to verify that the version of the J2SE SDK that is actually being used
is 1.4.2.
For more examples, see the files build.bat and run.bat in the bin directories of
the demonstration applications. You can find these files under the
{toolkit}\apps\<demo>\bin directory where {toolkit} is the installation directory of
the J2ME Wireless Toolkit and <demo> is the name of one of the demo applications.
103
B.2.1 Build
Using KToolbar, building a project is a single step. Behind the scenes, however,
there are actually two steps. First, Java source files are compiled into Java class
files. Next, the class files are preverified, which means they are prepared for the
CLDC KVM.
Use the javac compiler from the J2SE SDK to compile Java source files. You can
use the existing J2ME Wireless Toolkit project directory structure. You’ll need to
use the -bootclasspath option to tell the compiler to use the MIDP APIs, and
you’ll use the -d option to tell the compiler where to put the compiled class files.
The following example shows how you could compile a MIDP 2.0 application,
taking source files from the src directory and placing the class files in the
tmpclasses directory. Newlines have been added for clarity.
javac
-bootclasspath ..\..\lib\cldcapi10.jar;..\..\lib\midpapi20.jar
-d tmpclasses
src\*.java
If you want to use the optional APIs that are supported by the toolkit, add their
JAR files to the -bootclasspath option.
The next step is to preverify the class files. In the bin directory of the J2ME
Wireless Toolkit lives a handy utility called preverify. The syntax for the
preverify command is as follows:
preverify [options] <files | directories>
-classpath <classpath>
-d <output directory>
Specify the directory into which the preverifier should output classes. This
directory must exist before preverifying. If this option is not used, the preverifier
places the classes in a directory called output.
Following the example for compiling, use the following command to verify the
compiled class files. As before, newlines have been added for clarity.
preverify
-classpath ..\..\lib\cldcapi10.jar;..\..\lib\midpapi20.jar
-d classes
tmpclasses
B.2.2 Package
To package a MIDlet suite, you must create a manifest file, an application JAR, and
finally, a MIDlet suite descriptor.
Create a manifest file containing the appropriate attributes as specified in the MIDP
specification. You can use any text editor to create the manifest file. A manifest
might have the following contents, for example:
MIDlet-1: My MIDlet, MyMIDlet.png, MyMIDlet
MIDlet-Name: MyMIDlet
MIDlet-Vendor: My Organization
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0
Create a JAR file containing the manifest as well as the suite’s class and resource
files. To create the JAR file, use the jar tool that comes with the J2SE SDK. The
syntax is as follows:
jar cfm <file> <manifest> -C <class_directory> . -C <resource_directory> .
For example, to create a JAR file named MyApp.jar whose classes are in the
classes directory and resources are in the res directory, use the following
command:
jar cfm MyApp.jar MANIFEST.MF -C classes . -C res .
Create a JAD file containing the appropriate attributes as specified in the MIDP
specification. You can use any text editor to create the JAD file. This file must have
the extension .jad.
Note – You need to set the MIDlet-Jar-Size entry to the size of the JAR file
created in the previous step.
B.2.3 Run
You can run the emulator from the command line. The J2ME Wireless Toolkit’s bin
directory contains the command emulator. The syntax for the emulator
command is as follows:
emulator [options]
-Xquery: Print emulator skin information on the standard output stream and
exit immediately. The information includes the skin name, screen size, and other
capabilities.
-classpath <classpath>: Specify the classpath for libraries required to run the
application. Use this option when running an application locally.
Install the application with the specified JAD file onto a device.
run=[<storage_name> | <storage_number>]
transient=<jad_file_url>
Install, run, and remove the application with the specified JAD file.
Specifying transient causes the application to be installed and run and
then removed three times.
B.2.4 Debugging
You can use the following options with the emulator for debugging and tracing.
-Xverbose:<trace_options>
-Xdebug
-Xrunjdwp:<debug_settings>
transport=<transport_mechanism>
The transport mechanism used to communicate with the debugger. The only
transport mechanism supported is dt_socket.
address=<host:port>
The transport address for the debugger connection. You can omit providing a
host. If host is omitted, localhost is assumed to be the host machine.
server={y|n}
Start the debug agent as a server. The debugger must connect to the port
specified. The possible values are y and n. Currently, only y is supported (the
emulator must act as a server).
Command Description
DefaultDevice Pops up a dialog that allows you to choose the default emulator skin
ktoolbar Launches KToolbar
prefs Launches the toolkit preferences
utils Launches the toolkit utilities window
-Xprefs:<filename>
The filename you provide should be the full path name of a property file whose
values override the values in the preferences dialog box. The property file can
contain the following properties:
-Xdomain <domain_type>
JadTool only uses certificates and keys from J2SE keystores. J2SE provides
keytool, the command-line tool to manage J2SE keystores.
JadTool is packaged in a JAR file. To run it, open a command prompt, change the
current directory to {toolkit}\bin, and enter the following command:
java -jar JADTool.jar <command>
-help
Add the certificate of the key pair from the given keystore to the JAD file. The
default keystore is {toolkit}\appdb\_main.ks.
Add the digital signature of the given JAR file to the specified JAD file. The
default value for -jarfile is the MIDlet-Jar-URL property in the JAD file.
The default ME keystore is {toolkit}\appdb\_main.ks.
-encoding is UTF-8
-keystore is %HOMEPATH%\.keystore
-certnum is 1
-chainnum is 1
Before using MEKeyTool, you must first have access to a Java Cryptography
Extension (JCE) keystore. You can create one using the J2SE keytool utility; see
http://java.sun.com/j2se/1.4/docs/tooldocs/win32/keytool.html
for more information.
-help
Import a public key into the ME keystore from the given JCE keystore using
the given JCE keystore password. The default ME keystore is
{toolkit}\appdb\_main.ks and the default JCE keystore is
{user.home}\.keystore.
-list
List the keys in the ME keystore, including the owner and validity period for
each. The ME keystore is {toolkit}\appdb\_main.ks.
Delete a key from the given ME keystore with the given owner. The ME
keystore is {toolkit}\appdb\_main.ks.
B.6.1 Options
Option Description
TABLE 15 lists the features (delimited by commas) that can follow the -f option.
The wscompile tool reads a WSDL file, compiled service endpoint interface (SEI),
or model file as input. The Type of File column indicates which of these files can be
used with a particular feature.
B.6.1.1 Example
wscompile -gen -d generated config.xml
wscompile -gen -f:nounwrap -O -cldc1.1 -d generated config.xml
Internationalization
This appendix describes setting the language displayed in the J2ME Wireless
Toolkit and the localization setting of the emulation environment.
Some software uses a locale to tailor information for users, such as:
■ Messages displayed to the user
■ Fonts used or other writing-specific information
By default, all KToolbar strings, that is, the entire User Interface (UI), are displayed
in the language of the supported platform’s locale.
You can set the wtk.locale property to have the KToolbar displayed in a
specified locale’s language. For example, you can have the toolkit running on a
Japanese machine but still have the KToolbar display shown in English by setting
the locale property to en-US, and making sure that the proper supplement has
been downloaded and installed over the J2ME Wireless Toolkit. The wtk.locale
property should be placed in the
{toolkit}\wtklib\{platform}\ktools.properties file, where {platform} is the
name of the underlying platform (Windows or Linux, for example).
115
C.2 Emulated Locale
The microedition.locale property is the MIDP system property that defines
the current locale of the device, which is null by default. For the J2ME Wireless
Toolkit emulator, this value is automatically set to the default locale for the J2SE
environment you are running. For example:
■ If you are running in an English system in the US, the microedition.locale
is set to en-US.
■ If you are running in a French system, the microedition.locale is set to
fr-FR.
For details on setting a default locale, see the J2ME Wireless Toolkit Basic
Customization Guide.
You can override the default value by adding the javac.encoding property to
the {toolkit}\wtklib\{platform}\ktools.properties file, where {platform} is the
name of the underlying platform, like Windows or Linux. For example, if you are
running in an English system but find you need to compile a Japanese resource
bundle, you can specify a Japanese character set, such as:
javac.encoding=EUCJIS
You can override these fonts to support other characters that are not supported by
the default fonts. See the J2ME Wireless Toolkit Basic Customization Guide for
information on how to configure them.
A development cycle
full, 11
advanced configuration options, 26 simple, 7
application descriptor, 11
Application Management Software (AMS), 12
applications E
running remotely, 17 emulator, 29
applications directory, setting, 27 keyboard shortcuts, 32
attributes, 21 performance, 34
preferences, 32
B running solo, 36
skins, 29
building source code, 8 emulator command, 106
emulators
C default font support, 117
language support, 115
call graph, 41
encoding
CBS message, sending, 61
javac, 27
certificate importing, 55
certificate management, 54
certificate manager utility, 103 F
character encodings, 116 FileConnection API, 71
-classpath option, 104 managing roots, 72
command line operations, 103 font support, 117
command path, 103
G
D
generating stub from command line, 113
debugging, 17
from command line, 107
debugging options, 107 H
demonstrations, 79 heap size, 33
source code, 2 -help option, 106
deploying on a web server, 17
descriptor, 11
attributes, 21 I
-import command, 112
119
IrDA, 73 Mobile Media API (MMAPI), 65
capture, 66
formats and protocols, 65
J
JAD, 11
attributes, 21 N
creating, 11 Network Monitor
MIME type, 17 sorting messages, 46
JAR network monitor, 44
creating, 11 filtering, 45
MIME type, 17 sorting, 46
Java Cryptography Extension (JCE) keystore, 112 using with WMA, 64
JSR 184, 67
JSR 75, 71
O
OBEX, 73
K preferences, 74
key management, 52 obfuscation, 15
key pair installing ProGuard, 15
creating, 52 installing RetroGuard, 16
importing, 54 optional APIs, 3
keytool utility, 112
KToolbar
advanced configuration options, 26
P
application directory, 27 packaging
starting, 1, 5 example from command line, 105
ktools.properties, 27 packaging from command line, 104
ktools.properties file, 115 pausing and resuming, 35
performance, 34
permissions, 49
L persistent storage, 33
libraries, 25 Personal Information Management (PIM) API, 71
phone number, setting in emulator, 57
preverifying, 9
M example from command line, 104
managing certificates from command line, 112 profiler, 39
manifest file, creating, 105 call graph, 40, 41
memory monitor, 42 projects, 5, 19
graph, 42 attributes, 21
object details, 43 building, 8
messages creating, 6
sorting, 46 deploying on real devices, 14
messaging directory structure, 25
network simulation, 58 libraries, 25
method profiling, 39 MIDlets, 23
microedition.encoding property, 116 packaging, 11
microedition.locale property, 116 push registry, 24
MIDlets running, 9
in projects, 23 selecting APIs, 19
MIME types, 17 source code, 6
Mobile 3D Graphics API, 67 protection domains, 49, 50
proxy servers, 32
R
remotely-deployed applications, 17
revision control, 27
revision control files, 27
Revision Control System (RCS), 27
RevisionControl property, 27
run options, 106
Run via OTA, 12, 51
running
from command line, 106
S
signed MIDlet suites, 49
signing MIDlet suites, 51
SMS binary message, sending, 60
SMS text message, sending, 59
source code
creating, 7
location, 6
supported APIs, 3
T
Target Platform, 20
tracing options, 107
V
version control, 27
-version optopn, 106
W
Wireless Messaging API (WMA), 57
Wireless Toolkit
certificate manager utility, 103
running from command line, 103
Wireless Toolkit, setting locale, 115
WMA console, 59
wscompile tool, 113
wtk.locale property, 115
X
-Xdebug option, 107
-Xquery option, 107
-Xrunjdwp option, 107
-Xverbose option, 107
Index 121
122 J2ME Wireless Toolkit User’s Guide • October 2004