Professional Documents
Culture Documents
Copyright 2007 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this document. In particular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents or pending patent applications in the U.S. and in other countries. 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. Use is subject to license terms. This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo, Java, Jini, Solaris, J2SE, Java SE, J2ME, Java ME, Netbeans, java, the Duke logo 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 is a registered trademark of Adobe Systems, Incorporated. Sprint, the "Going Forward" logo, and other trademarks are trademarks of Sprint Nextel. This product is covered and 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 identied on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited.
Copyright 2007 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, Etats-Unis. Tous droits rservs. Sun Microsystems, Inc. dtient les droits de proprit intellectuels relatifs la technologie incorpore dans le produit qui est dcrit dans ce document. En particulier, et ce sans limitation, ces droits de proprit intellectuelle peuvent inclure un ou plus des brevets amricains lists l'adresse http://www.sun.com/patents et un ou les brevets supplmentaires ou les applications de brevet en attente aux Etats - Unis et dans les autres pays. L'utilisation est soumise aux termes de la Licence. Cette distribution peut comprendre des composants dvelopps par des tierces parties. Sun, Sun Microsystems, le logo Sun, Java, Jini, Solaris, J2SE, Java SE, J2ME, Java ME, Netbeans, java, le logo Duke et le logo Java Coffee Cup sont des marques de fabrique ou des marques dposes de Sun Microsystems, Inc. aux Etats-Unis et dans d'autres pays. Le logo Adobe est une marque dpose de Adobe Systems, Incorporated. Sprint, the "Going Forward" logo, and other trademarks are trademarks of Sprint Nextel . Ce produit est soumis la lgislation amricaine en matire de contrle des exportations et peut tre soumis la rglementation en vigueur dans d'autres pays dans le domaine des exportations et importations. Les utilisations, ou utilisateurs naux, pour des armes nuclaires,des missiles, des armes biologiques et chimiques ou du nuclaire maritime, directement ou indirectement, sont strictement interdites. Les exportations ou rexportations vers les pays sous embargo amricain, ou vers des entits gurant sur les listes d'exclusion d'exportation amricaines, y compris, mais de manire non exhaustive, la liste de personnes qui font objet d'un ordre de ne pas participer, d'une faon directe ou indirecte, aux exportations des produits ou des services qui sont rgis par la lgislation amricaine en matire de contrle des exportations et la liste de ressortissants spciquement dsigns, sont rigoureusement interdites.
Contents
Preface 1.
xiii 11 11 12
Quick Start
Supported Technology
14 21
2.
The Simple Development Cycle 2.2.1 Source Code Open With 2.2.2 2.2.3 Build Run 26 27 25 25
24
2.3
The Full Development Cycle 2.3.1 2.3.2 2.3.3 Package Install Run 29 210 212
28
2.4
213
iii
Creating a Project from a MIDlet Suite Using an Obfuscator Using a Debugger 215
214
217 220
Working With Projects 3.1 3.2 3.3 3.4 3.5 3.6 Selecting APIs
31 33
Changing MIDlet Suite Attributes Manipulating MIDlets Using the Push Registry 35 37 38 38 39
Project Directory Structure Using Third-Party Libraries 3.6.1 3.6.2 3.6.3 Using External APIs
Third-Party Libraries for One Project Third-Party Libraries for All Projects 312 312
311 311
3.7
4.
Emulator Controls
Setting Emulator Preferences 4.3.1 4.3.2 4.3.3 4.3.4 Network Proxies Heap Size 47 46
47 48
iv
410 410
Multitasking VM and the Emulator Running the Emulator Solo Using Third Party Emulators Additional Sprint Features 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 412 413
413 413
5.
Monitoring Applications 5.1 Using the Profiler 5.1.1 5.1.2 5.1.3 5.2 5.3
54 54
Using the Monty Memory Observe Tool Using the Network Monitor 5.3.1 5.3.2 5.3.3 5.3.4 Filtering Messages Sorting Messages 59 511 511
Saving and Loading Network Monitor Information Clearing the Message Tree 512 61 512
512
5.4 6.
Tracing
Contents
62
63
73 74 74
Signing a MIDlet Suite Signing a GCD File Managing Keys 7.5.1 7.5.2 7.5.3 7.5.4 78 76
Creating and Using Keystores Creating a New Key Pair Getting Real Keys 712 713 710
78
7.6
Enabling and Disabling Certificates Importing Certificates Removing Certificates 715 715 81 81 82
714
8.
Sending Messages With the WMA Console 8.3.1 8.3.2 Sending a Text SMS Message 84 85
83
vi
8.3.3 8.4 9.
86 88
Well-Behaved MIDlets
10.
Rendering Scalable Vector Graphics (SVG) Content Using the Mobile 3D Graphics API 10.2.1 10.2.2 10.2.3 10.2.4 Immediate Mode Retained Mode 102 102 103 103 102
101
11.
Using the PIM and FileConnection APIs 11.1 11.2 The FileConnection API The PIM API 113 121 111
12.
Bluetooth Simulation Environment Setting Bluetooth Preferences 12.2.1 12.2.2 12.2.3 121
121
Bluetooth Internal Properties Bluetooth System Properties Bluetooth BCC Properties 131 141
122 122
123
13. 14.
141
Contents
vii
143
Using the Java Card Platform Simulator Adjusting Access Control 15.3.1 15.3.2 15.3.3 153 153
152
154
16.
161
17.
Working with the Payment API 17.1 17.2 17.3 17.4 17.5
171 174
18.
Using the Mobile Internationalization API 18.1 18.2 18.3 18.4 18.5 Setting the Emulators Locale Viewing Application Resources Working With Locales 183 183 181 181
181
183 191
19.
viii
191 191
196
19.4
System
A. Application Demonstrations A.1 A.2 A.3 A.4 A.5 A.6 A.7 A.8 Overview A1
General Instructions
A4 A7
Advanced Multimedia Supplements Bluetooth Demo CHAPIDemo CityGuide DebugApp Demo3D A.8.1 A.8.2 A.8.3 A9
A10
Life3D
PogoRoo
A.9
A22
Working with Settings Stock Tracker What If? Alerts A24 A23
A22
A23
A23
A.9.6
Tickets
Contents
ix
A.9.7
ManyBalls
A25
A.13 JSR172Demo
A.16.4 Attributes for MobileMediaAPI A.17 MP4Player Demo A.18 Muglet Demo A40
A43 A45
A47 A48
A.22.1 Browsing Files A.22.2 Browsing Files A.22.3 The PIM API A.23 Razr2Demo A55
A56
A62 A62
A63
A.25.3 CryptoMIDlet A.25.4 MohairMIDlet A.26 SATSAJCRMIDemo A.27 SIPDemo A64 A65
A63 A63
A64
A.28 SprintDemo
A.28.1 External Canvas Demo A.28.2 SystemStates Demo A.28.3 Media Demo A.29 SVGContactList A.30 SVGDemo A70 A71 A68
A65
A66
A69
A.30.4 Create SVG Image From Scratch A.30.5 Bouncing Balls A72 A72 A73 A75
B1
B1
Package Run B4
Debugging
B5
Contents
xi
Launching Toolkit GUI Components Setting Emulator Preferences Using Security Features B.5.1 B.5.2 B.5.3 B8 B6
B6
Changing the Emulators Default Protection Domain Signing MIDlet Suites Managing Certificates C1 C1 C2 C2 C3 B9 B10
B9
Locale Setting
Emulated Locale
Character Encodings
xii
Preface
This document describes how to work with Sprint Wireless Toolkit 3.2 Powered by Sun Java Technology (the toolkit).
Related Documentation
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 Suns mobility web site: http://developers.sun.com/techtopics/mobility/
Preface
xiii
Related Documentation
Title
Release Notes CLDC 1.0 - JSR 30 MIDP 1.0 - JSR 37 PDAP Optional Packages - JSR 75 Bluetooth and OBEX - JSR 82 MIDP 2.1 - JSR 118 WMA 1.1 - JSR 120 CLDC 1.1 - JSR 139 MMAPI - JSR 135 J2ME Web Services - JSR 172 SATSA - JSR 177 Location API - JSR 179 SIP API - JSR 180 Mobile 3D Graphics - JSR 184 JTWI - JSR 185 WMA 2.0 - JSR 205 CHAPI 1.0 - JSR 211 SVG API - JSR 226 Payment API (PAPI) - JSR 229 AMMS - JSR 234 MIA- JSR 238 MSA - JSR 248
Sprint Wireless Toolkit 3.2 Powered by Sun Java Technology Release Notes J2ME Connected Limited Device Configuration Mobile Information Device Profile for the J2ME Platform PDA Optional Packages for the J2ME Platform Java APIs for Bluetooth Mobile Information Device Profile 2.0 (Final Release 2 is referred to as MIDP 2.1) Wireless Messaging API 1.1 J2ME Connected Limited Device Configuration Mobile Media API J2ME Web Services Specification Security and Trust Services APIs for J2ME Location API for J2ME SIP API for J2ME Mobile 3D Graphics API for J2ME Java Technology for the Wireless Industry Wireless Messaging API (WMA) Content Handler API Scalable 2D Vector Graphics API for J2ME Payment API Advanced Multimedia Supplements Mobile Internationalization API Mobile Service Architecture
xiv
Preface
xv
Appendix A describes the application demonstrations that are included in the toolkit. Appendix B explains how to use the functionality of the toolkit from the command line. Appendix C describes localization features in the toolkit.
Typographic Conventions
TABLE P-2 Typeface Meaning Examples
AaBbCc123
The names of commands, files, Edit your .login file. and directories; on-screen Use ls -a to list all files. computer output % You have mail. What you type, when contrasted with on-screen computer output Book titles, new words or terms, words to be emphasized Command-line variable; replace with a literal value % su Password: Read Chapter 6 in the Users Guide. These are called class options. You must be superuser to do this. To delete a file, type: rm filename In the book, toolkit always refers to the installation directory of the Sprint Wireless Toolkit.
AaBbCc123
AaBbCc123
AaBbCc.dir
xvi
Preface
xvii
xviii
CHAPTER
Introduction
This book describes how to use Sprint Wireless Toolkit 3.2 - Powered by Java Technology (the toolkit). The 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.1, the toolkit also supports many optional packages, making it a widely capable development toolkit.
1.1
Quick Start
If youd like to get started right away, try the demonstration applications that are included with the toolkit. To run the demonstrations, start KToolbar. On Microsoft Windows choose Start > Programs > Sprint Wireless Toolkit 3.2 - Powered by Java Technology > KToolbar.1 You see a window like that shown in FIGURE 1-1.
1. Depending on how Microsoft Windows is configured, you might need to choose Start > All Programs instead of Start > Programs.
1-1
FIGURE 1-1
To open a demonstration application, click the Open Project... button. A window displays a list of projects. Pick a project and click the Open Project button at the bottom of the window. The demonstration application opens. Press the Run button. The emulator pops up running the application. Most demonstrations are self-explanatory, but some have additional instructions. See Appendix A for additional details. 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.
1.2
KToolbar automates many of the tasks involved in creating MIDP applications. The emulator is a simulated mobile phone. It is useful for testing MIDP applications.
1-2
A collection of utilities provides other useful functionality, including a text messaging console and cryptographic utilities.
KToolbar is the center of the toolkit. You can use it to build applications, launch the emulator, and start the utilities. Alternately, the emulator and utilities can be run by themselves, which is useful in many situations. If you want to demonstrate MIDP applications, for example, its useful to run the emulator by itself. The only additional tool you need is a text editor for editing source code.
1.3
Toolkit Features
The toolkit supports the creation of MIDP applications with the following main features:
Building and packaging: You write the source code and the toolkit takes care of the rest. With the push of a button, the toolkit compiles the source code, preverifies the class files, and packages a MIDlet suite. Running and monitoring: You can run a MIDlet suite directly in the emulator or install it using a process that resembles application installation on a real device. A memory monitor, network monitor, and method profiler are provided to analyze the operation of your MIDlets. MIDlet suite signing: The toolkit contains tools for cryptographically signing MIDlet suites. This is useful for testing the operation of MIDlets in different protection domains.
Chapter 1
Introduction
1-3
1.4
Supported Technology
The toolkit supports many standard Application Programming Interfaces (APIs) defined through the Java Community Process (JCP). TABLE 1-1 shows the APIs and includes links to the specifications.
TABLE 1-1 JSR API
JSR 75 PIM and File JSR 82 Bluetooth and OBEX JSR 118 MIDP 2.1 JSR 120 WMA 1.1 JSR 135 MMAPI 1.1 JSR 139 CLDC 1.1 JSR 172 Web Services JSR 177 SATSA JSR 179 Location JSR 180 SIP JSR 184 3D Graphics JSR 185 JTWI 1.0 JSR 205 WMA 2.0
PDA Optional Packages for the J2ME Platform http://jcp.org/en/jsr/detail?id=75 Java APIs for Bluetooth http://jcp.org/en/jsr/detail?id=82 Mobile Information Device Profile http://jcp.org/en/jsr/detail?id=118 Wireless Messaging API http://jcp.org/en/jsr/detail?id=120 Mobile Media API http://jcp.org/en/jsr/detail?id=135 Connected Limited Device Configuration http://jcp.org/en/jsr/detail?id=139 J2ME Web Services Specification http://jcp.org/en/jsr/detail?id=172 Security and Trust Services API for J2ME http://jcp.org/en/jsr/detail?id=177 Location API for J2ME http://jcp.org/en/jsr/detail?id=179 SIP API for Java ME http://jcp.org/en/jsr/detail?id=180 Mobile 3D Graphics API for J2ME http://jcp.org/en/jsr/detail?id=184 Java Technology for the Wireless Industry http://jcp.org/en/jsr/detail?id=185 Wireless Messaging API http://jcp.org/en/jsr/detail?id=205
1-4
JSR 211 CHAPI JSR 226 SVG JSR 229 PAPI JSR 234 AMMS JSR 238 MIA JSR 248 MSA
Content Handler API http://jcp.org/en/jsr/detail?id=211 Scalable 2D Vector Graphics for J2ME http://jcp.org/en/jsr/detail?id=226 Payment API http://jcp.org/en/jsr/detail?id=229 Advanced Multimedia Supplements http://jcp.org/en/jsr/detail?id=234 Mobile Internationalization API http://jcp.org/en/jsr/detail?id=238 Mobile Service Architecture http://jcp.org/en/jsr/detail?id=248
Chapter 1
Introduction
1-5
1-6
CHAPTER
2.1
About Projects
In the toolkit, MIDlet suites are organized into projects, where the end result of one project is one MIDlet suite. A project contains all of the files that are used to build a MIDlet suite, including Java source files, resource files, and the MIDlet descriptor. The toolkit works on one project at a time. You can create a new project or open an existing project. In this chapter you 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 Microsoft Windows, choose Start > Programs > Sprint Wireless Toolkit 3.2 - Powered by Java Technology > KToolbar.1 You see the KToolbar window.
1. Depending on how Microsoft Windows is configured, you might need to choose Start > All Programs instead of Start > Programs.
2-1
FIGURE 2-1
Click New Project... An appropriate directory is supplied by default. Enter the Project Name. Leave the Package Name field empty. In the MIDlet Class Name field, enter TinyMIDlet. Uncheck the Generate sample MIDlet box. Click Create Project.
2-2
FIGURE 2-2
The Settings window opens with API Selection displayed so that you can set up the build environment for the project. The default options are fine for this example, so click OK to dismiss the window. In the KToolbar console, you see some messages telling you exactly where to store the source code and resource files for this project.
Chapter 2
2-3
FIGURE 2-3
2.2
2-4
2.2.1
Source Code
You can use the text editor of your choice to create and edit source code files. (If you dont have a favorite text editor, try jEdit, at http://jedit.org/.) If you are following along with the example project, create a new Java source file TinyMIDlet.java. It should be saved in the source directory of your project, which is toolkit\apps\Tiny\src\TinyMIDlet.java where toolkit is the installation directory of the toolkit. The file contains a very simple MIDlet:
import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet; public class TinyMIDlet extends MIDlet implements CommandListener { public void startApp() { Display display = Display.getDisplay(this); Form mainForm = new Form("TinyMIDlet"); mainForm.append("Welcome to the world of MIDlets!"); Command exitCommand = new Command("Exit", Command.EXIT, 0); mainForm.addCommand(exitCommand); mainForm.setCommandListener(this); display.setCurrent(mainForm); } public void pauseApp () {} public void destroyApp(boolean unconditional) {} public void commandAction(Command c, Displayable s) { if (c.getCommandType() == Command.EXIT) notifyDestroyed(); } }
Open With
The main window displays the hierarchy of the open project. Within the hierarchy, you can open a file with an external application. Right-click the file and select Open With... as shown in FIGURE 2-4.
Chapter 2
2-5
FIGURE 2-4
Choose Program - select a .jar or .exe file that launches a program. For example, you might want to open a source file in a text editor. When you select the application, it application opens the selected file. At that time the toolkit also adds the programs name to the Open With menu. Remove Entries - This option clears the list of programs on the Open With menu.
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 the Build button. Assuming you saved your source file in the right place, the toolkit finds it and compiles it. Compilation errors are displayed in the KToolbar console. If you have errors, go back and edit the source code to fix them. Once youve eliminated your errors, the KToolbar console tells you the project was successfully built.
2-6
FIGURE 2-5
Behind the scenes, the 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 wont ever realize its 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 the Run button. If youre following along with the TinyMIDlet example, the emulator show something like FIGURE 2-6:
Chapter 2
2-7
FIGURE 2-6
TinyMIDlet in Action
2.3
2-8
2.3.1
Package
The 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. Open a project. In the main window, select a MIDlet suite, then choose Project > Package > Create Package from the KToolbar menu, or click the Package button, as shown in FIGURE 2-7. The MIDlet suite descriptor and JAR are generated and placed in the selected projects bin directory.
FIGURE 2-7
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 toolkit provides tools to allow you to cryptographically sign MIDlet suites. See Chapter 7 for more information.
Chapter 2
2-9
2.3.2
Install
To properly test a MIDlet suite, you should install it into the toolkits emulator or a real device. When you press the Run button in KToolbar, the MIDlet suite is not installed into the emulator. Instead, the emulator runs the MIDlet classes directly. 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 the current application in the toolkit emulator, choose Project > Run via OTA or click the Run via OTA button. The emulator window opens, but instead of running your MIDlet classes directly, this time the emulator shows the welcome screen of its Application Management Software (AMS). The emulators AMS is an example of the type of software that real devices must have to manage MIDlet suites.
FIGURE 2-8
Select Install Applications. Select the Launch soft menu button. The emulator prompts you for the URL location of the application you want to install. In the demos provided the URL is already filled in for you.
2-10
FIGURE 2-9
URL Prompt
Choose 2 (Go to) from the menu to begin the installation. After a download, the emulator shows a list of the applications it finds at the URL. Choose one and click the Install soft button. The emulator gives you one last chance to confirm your intentions.
FIGURE 2-10
Choose Install again. You might see a security confirmation message. Press Continue. You are asked if you want to launch Tiny.jad. Click the OK soft button and you see the MIDlets welcome message. Select Exit and you are returned to the Applications screen. Tiny is now listed as an installed application.
Chapter 2
2-11
FIGURE 2-11
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 must 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 encounter when the 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 wont 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, choose the application from the list and choose Launch from the menu.
2-12
FIGURE 2-12
Running an application on a real device depends heavily on the device itself. Consult your device documentation for information.
2.4
Chapter 2
2-13
FIGURE 2-13
2.5
2-14
FIGURE 2-14
2.6
Using an Obfuscator
An obfuscator is a tool that reduces the size of class files. MIDlet suites need to be compact, both to minimize download times and to comply with sometimes stringent limits on JAR size imposed by manufacturers or carriers. Using an obfuscator is one way (not the only way) that you can keep your MIDlet suite JAR small. You can use an obfuscator in the packaging step of the development cycle. Although the toolkit doesnt 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.
Chapter 2
2-15
Installing ProGuard in the toolkit is straightforward: 1. Go to the ProGuard web site, http://proguard.sourceforge.net/. 2. Download the latest version. 3. Uncompress the proguard.jar file from the lib directory of the ProGuard installation to the bin directory of your toolkit installation. Once ProGuard is installed, you can use it by choosing Project > Package > Create Obfuscated Package. In some cases you must 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 projects 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 need to quit and restart KToolbar for the change to take effect. The toolkit also includes support for RetroGuard. If you want to use RetroGuard, you must download it separately and change the toolkits configuration. 1. Go to the RetroGuard web site, http://www.retrologic.com/retroguardmain.html. 2. Download the latest version. 3. Extract the retroguard.jar file from downloaded zip file to the bin directory of your toolkit installation. 4. Edit toolkit\wtklib\platform\ktools.properties so that it uses the RetroGuard obfuscator plug-in:
obfuscator.runner.class.name: com.sun.kvem.ktools.RunRetro obfuscator.runner.classpath: wtklib\\ktools.zip
Retroguard is used when you create an obfuscated package. To switch back to ProGuard, edit the obfuscator lines in the ktools.properties file as follows:
obfuscator.runner.class.name: com.sun.kvem.ktools.RunPro obfuscator.runner.classpath: wtklib\\ktools.zip
2-16 Sprint Wireless Toolkit 3.2 Users Guide December 2007
If you want to use a different obfuscator, you must implement an obfuscator plug-in yourself.
2.7
Using a Debugger
A variation on running your application is running it with a debugger. A debugger allows you to monitor the running application more closely, set breakpoints, and examine variables. You must supply your own debugger. You can use the jdb debugger from J2SE or another debugger of your choice. If you want to use a debugger, you are likely to use an Integrated Development Environment (IDE) that is aware of the toolkit. For example the NetBeans Mobility pack. See http://www.netbeans.org/products/mobility/. Information about using jdb with the toolkit is here:
http://developers.sun.com/techtopics/mobility/midp/questions/jdb/
The general steps for debugging are as follows: 1. Choose Project > Debug from the KToolbar menu. 2. Enter the TCP/IP port number that the debugger must use to connect to the emulator. Click Debug. The port number can be any legal port between 1024 and 65546. When you click Debug, the emulator begins running and waits for a connection from a debugger. 3. Start up your debugger and attach it to the port you specified. Make sure to set the debugger to run in remote mode and to use TCP/IP. For more information, consult the debuggers documentation. The following procedure applies these steps using the NetBeans IDE and the toolkit.
In NetBeans, select Tools > Java Platforms. In the Platforms area under the J2ME you must have a platform named Sprint Wireless Toolkit Powered by Sun Java Technology. Note that the platform name does not have a version number. To
Chapter 2
2-17
add this platform, click Add Platform and use the wizard to add a Java ME MIDP Platform Emulator of that name and specify the path to your Sprint Wireless Toolkit 3.2 installation.
You might need to customize your firewall settings or disable your firewall to ensure the toolkit successfully attaches to the external debugger.
1. Launch KToolbar and open a project. 2. In NetBeans, open the same toolkit project and view the source. a. Open a source file. In this example we use the UIDemo project and open TextFieldDemo.java. b. Place the cursor in a method and type CTRL-F8 to set a breakpoint The breakpoint is highlighted in red, as shown in FIGURE 2-15.
FIGURE 2-15
3. In KToolbar, open the project with the breakpoint. a. Select Project > Debug. Accept the default port number as shown in FIGURE 2-16, or enter any number between 1024 and 65536.
2-18
FIGURE 2-16
b. Click Debug. The emulator runs. Before it launches you see the following benign messages in the console: KVMListener: Exception java.net.ConnectException: Connection refused: connect KVM not ready 4. In the NetBeans IDE, right-click the Debug Main Project button and select Attach Debugger... as shown in FIGURE 2-17.
FIGURE 2-17
5. In the Attach window (FIGURE 2-18), set the host to localhost, and specify the same port number that you specified in Step 3. Click OK. The connection is made. In the NetBeans IDE debugger console you see the following message: Attaching to 127.0.0.1:5000 User program running When the connection succeeds the MIDlet is started in the emulator.
Chapter 2
2-19
FIGURE 2-18
Attach Window
6. Launch the application (in this case TextFieldDemo). The application stops at the breakpoint. In NetBeans, the breakpoint is now colored green.
2.8
Next, ensure that the Web server uses the correct MIME types for JAD and JAR files:
For MIDlet suite descriptors, map the .jad extension to the text/vnd.sun.j2me.app-descriptor MIME type. For MIDlet suite JARs, map the .jar extension to the application/javaarchive MIME type.
The details of how to configure a Web server depend on the specific software used.
2-20
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 emulators AMS. You may already be familiar with the AMS if you have used the Run via OTA option. To launch the emulators AMS, you have two options:
In the Microsoft Windows start menu, choose Start > Programs > Sprint Wireless Toolkit 3.2 - Powered by Java Technology> OTA Provisioning. From the command line, run: 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 must enter the URL of your own server to install your application.
Chapter 2
2-21
2-22
CHAPTER
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
3.1
Selecting APIs
Each project is built against some set of APIs. The toolkit supports many APIs; the full list is detailed in Chapter 1. The toolkit allows you to develop applications for some subset of APIs based on the type of devices you expect to run your software. For example, even though the toolkit supports JSR 184, the Mobile 3D Graphics API, you might want to develop applications that dont make use of that API. The projects 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. Click Settings... to bring up the window shown in FIGURE 3-1.
3-1
FIGURE 3-1
3-2
On the API Selection pane, the Target Platform setting controls the appearance of the rest of the pane. Choose the setting that best suits your need and select optional APIs or extensions. 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.
3.2
Note If you change any settings on an existing project you must package and sign
the project again. See Section 7.3, Signing a MIDlet Suite on page 7-5. To see the attributes, run KToolbar and open a project and click Settings.... The Settings window divides attributes into Required, Optional, and User Defined groups. Consult the MIDP 2.0 specification for the definitions of the required and optional attributes. The toolkit takes care of most of the details. In the early stages of development, you might not have to worry about the attributes, so you can just click OK to accept the defaults. Once your application is stable and youre starting to think about deploying on real devices and going to market, you should come back and adjust the values. To change an attribute, from the Settings window, select the Required, Optional, or User Defined icon on the left, as shown in FIGURE 3-2. Click in the cell next to the attribute key you wish to change. While you are editing a value the OK button is disabled. When you leave a field (for example, you type Tab to move to another field), the toolkit performs a validation. If the value you edited is invalid, you receive an error message. See FIGURE 3-3.
Chapter 3
3-3
FIGURE 3-2
FIGURE 3-3
3-4
To create new user-defined attributes, click the User Defined icon. 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 Remove if you wish to remove the key and value entirely.
3.3
Manipulating MIDlets
The project settings also provide a way to add or modify the MIDlets that are contained in the current MIDlet suite project. To see how this works, start the toolkit and open an existing project. Click Settings... and choose the MIDlets pane. You see a list of all MIDlets in the project. If you just created a new project, the toolkit automatically fills in the first MIDlet entry.
Note If you change any settings you must package and sign the project again. See
Section 7.3, Signing a MIDlet Suite on page 7-5.
Chapter 3
3-5
FIGURE 3-4
To add a new MIDlet, click 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. The MIDlet names are presented to the user in the order shown when the MIDlet suite is launched. You can modify the order by selecting a MIDlet and clicking Move Up or Move Down. FIGURE 3-4 shows the Demo project MIDlets been placed in alphabetical order by name.
3-6
3.4
FIGURE 3-5
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.
Chapter 3
3-7
If you do make push registry entries for your application, make sure you also enter the appropriate permissions. See Chapter 7 for details.
3.5
The MIDlet suite descriptor and JAR are placed in this directory when you package the project. This directory is used by the toolkit to store compiled class files. Place a third-party library in this directory to include it in this project. Images, sounds, and other resource files go in this directory. They are packaged into the root of the MIDlet suite JAR. Place source files in this directory. This directory is used by the toolkit. This directory is used by the toolkit.
In addition, the project directory contains a project.properties file which contains information about the project. If you want to remove temporary directories and files from the project, choose Project > Clean from the KToolbar menu.
3.6
3-8
When you use a third-party library in your application, your JAR expands by the size of the third-party library. You can use an obfuscator to reduce the code size, and a good obfuscator even eliminates portions of the library that you are not using. Even with the use of an obfuscator, a third-party library is probably larger than your own custom code, carefully written from scratch. You must evaluate the trade-off between reducing your development time and the size of your MIDlet suite JAR. The toolkit supplies two methods for incorporating third-party libraries. The External APIs pane in the project settings makes it easy to include or exclude libraries in a project. In addition, you can place libraries in specific locations to make them available to one or all projects.
3.6.1
Chapter 3
3-9
FIGURE 3-6
The API is added to the list. To add the API to the classpath at build time, check the box in the Use column (see FIGURE 3-7). If you intend to deploy your application on devices where your selected external APIs are not present, you must bundle those APIs in your application. To bundle the API into your application, check the Bundle box. Click OK when you are finished.
3-10
FIGURE 3-7
The External APIs tab shows all JARs in the toolkit\lib\ext directory. If the manifest file for a JAR contains an API-Name attribute, the name is shown. If the attribute is missing, the name of the file is shown instead.
3.6.2
3.6.3
Chapter 3
3-11
3.7
Configuring KToolbar
KToolbar includes some advanced configuration options. You can use these options by editing the toolkit\wtklib\platform\ktools.properties file. To see the effects of your changes, restart KToolbar.
3.7.1
3.7.2
Any backslash ('\') characters in the directorys path should be preceded by another backslash. Also, the directorys path should not contain any spaces. For example, to set the application directory to D:\dev\midlets, you would use:
kvem.apps.dir: D:\\dev\\midlets
3.7.3
3-12
3.7.4
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.
Chapter 3
3-13
3-14
CHAPTER
4.1
Emulator Skins
A skin is a thin layer on top of the emulator implementation that provides it with a certain appearance, screen characteristics, and input controls. The toolkit comes with skins that represent different kinds of devices. The toolkit supports skins from Sprint MIDP 1.0 Vision, MIDP 2.0 Vision, and MIDP 2.0 Power Vision, and MIDP 2.0 Multitasking VM (MVM) platforms. Make a selection from the Platform menu (FIGURE 4-1) and the supported devices are shown on the Devices tab.
4-1
FIGURE 4-1
To view the specification for a given emulator skin, go to the Devices tab, right-click a device, and select Devices spec... from the context menu (FIGURE 4-2).
FIGURE 4-2
4.2
Emulator Controls
The emulator looks and acts like a mobile phone inside a standard desktop window. In this section you learn how to control the emulator. Although the description and figures are based on the SamsungA900 skin, all the skins operate in a similar way.
4-2
FIGURE 4-3
You can use the mouse to click the buttons. Most buttons also have keyboard shortcuts, which are generally easier to use. Keyboard numbers 0 through 9 correspond to the emulators 0 through 9 buttons. Some less obvious keyboard shortcuts are in TABLE 4-1.
Chapter 4
4-3
TABLE 4-1
Keyboard Shortcuts
Keyboard key
Emulator button
F1 F2 Esc Enter
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 most users do not have. Another convenience is the capability to copy and paste information in text areas. You can paste text from the clipboard into a TextBox or TextField by pressing Ctrl-V. To copy the contents of a TextBox or TextField, press Ctrl-C. The contents of the text field are placed on the clipboard. The UIDemo is useful for trying the different types of input methods. For example, you might select a text box. You then have the option to select a text box type, as shown in FIGURE 4-4. The selection Any Character results in the choices in FIGURE 4-4. In this MIDlet the programmer has predetermined the input method. For each field, there is a tooltip that hints the expected method.
4-4
FIGURE 4-4
If you select Any Character you see something like FIGURE 4-5. Note the tooltip hinting that Qwerty (keyboard) input is expected. Other input types are 123 (numeric) and ABC (text). These modes imply you can use the skin to enter numbers and text, respectively. Usually you can also use the keyboard to enter the information, as long as it complies.
FIGURE 4-5
Qwerty Mode
FIGURE 4-6 shows the Number field with the numeric 123 tooltip.
Chapter 4
4-5
FIGURE 4-6
4.3
4.3.1
Network Proxies
The emulator uses your desktop network connection. For example, if the emulator runs a MIDlet that makes an HTTP connection, the emulator attempts to make the HTTP connection using the desktops network setup. If your development computer is behind a firewall, you might use a proxy server to make HTTP connections. If youre not sure, try examining your browsers 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 pane, check Use proxy server and fill in the names and port numbers for the proxy server. You can also select which version of HTTP you wish to use. If your proxy servers use HTTP Basic authentication (see RFC 2617), check Authentication and fill in the user name and password.
4-6
4.3.2
Heap Size
The heap is memory where your applications objects are stored. Many real devices have limited heap size. You can set a maximum heap size to more closely simulate the conditions on a real device. Choose Edit > Preferences... from the KToolbar menu and selecting the Storage item. Fill in the maximum heap size in the Heap Size field. Remember, one kilobyte (kB) is 1024 bytes. If you dont specify a heap size, the default is 1 megabyte.
FIGURE 4-7
4.3.3
Note If multiple instances of the same emulator skin run simultaneously, the
toolkit generates unique file paths for each one. For example, a second instance of SamsungA940 might have a file path name of toolkit\appdb\ temp.SamsungA9401139929445509. The toolkit enables you to choose a different location for the storage files, and you can limit the size of the storage. This is useful if you wish to test your applications behavior when a small amount of persistent storage is available. To adjust the persistent storage settings, choose Edit > Preferences... and click Storage in the left pane. 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.
Chapter 4
4-7
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 the Clean Database button to wipe the persistent storage clean.
4.3.4
4-8
FIGURE 4-8
Adjust the Graphics primitives latency to have an effect on the amount of time that elapses between your applications 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 must also 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.
Chapter 4
4-9
4.4
MIDP 1.0 Vision, MIDP 2.0 Vision, and MIDP 2.0 Power Vision When the emulator is running, choose MIDlet > Pause MIDlet. To resume the MIDlets operation, choose MIDlet > Resume MIDlet.
MIDP 2.0 MVM Platform When running a Multitasking VM device in OTA mode, select MIDlet > Pause VM. The resume action is handled from the AMS menu as described in Section 4.5, Multitasking VM and the Emulator on page 4-10. When you run locally the option is Pause MIDlet and Resume MIDlet.
4.5
4-10
FIGURE 4-9
To start another application, return to the application manager. If the MIDlet has been programmed with the Multitasking VM in mind the application might automatically go to the background after you press End, or, you can use Send to Background to send the application to the background manually. Resume application returns you to the first application, and Exit application closes the application without closing the emulator. 3. In the AMS, launch a second MIDlet. 4. In the second MIDlet, press END to return to the AMS. The AMS shows that two MIDlets are running simultaneously (FIGURE 4-10). MIDlets with green checks are running.
FIGURE 4-10
When running multiple applications using the End key to move from the application to the AMS.
Chapter 4
4-11
The MIDlet determines what happens when it is in the back ground. For example you can program the following behaviors:
Allow an application, such as a media player, to remain audible while in the background. Suspend games when they are in the background. Launch applications in the background at boot time. For example, instant messaging, stock tickers, news, and more. Use alerts to notify the user when something interesting happens in a background application.
To see the Multitasking VM in action, go to installdir/docs/MVMTutorialMovie and run the .html file, or try Section A.19, Multitasking VM Demo on page A-45.
4.6
To run an application directly, which is analogous to pressing KToolbars Run button, choose the Run MIDP Application... item. The toolkit prompts you to locate a MIDlet descriptor file on your local disk. Note that the corresponding MIDlet suite JAR must also be present. To run the emulators Application Management Software (AMS), choose the OTA Provisioning item, which is roughly analogous to KToolbars 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 emulators 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 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 for more information.
4-12
4.7
4.8
4.8.1
Chapter 4
4-13
FIGURE 4-11
Project Tree
To expand the tree, click + or double-click on a directory name. You see the files or resources in each directory. To open a file or resource, double-click its name or right-click the name and select Open (see FIGURE 4-12). This opens the resource using your system default application. For example, Notepad.
4-14
FIGURE 4-12
As shown in FIGURE 4-13, open with allows you to choose a program. The Open With menu options are as follows:
Choose Program - select a .jar or .exe file that launches a program. For example, you might want to open a source file in a text editor. When you select the application, it application opens the selected file. At that time the toolkit also adds the programs name to the Open With menu. Remove Entries - This option clears the list of programs on the Open With menu.
Chapter 4
4-15
FIGURE 4-13
To add a new or existing source or resource file, right-click one of the directory names and make a selection from the context menu. Add existing allows you to browse for a file and copies the selected file into the selected directory (see FIGURE 4-14). Add new opens a dialog in which you specify the file name.
FIGURE 4-14
4-16
You can also drag and drop a file into the projects tree from the Windows explorer.
4.8.2
Device Selection
You can select the device that appears in the emulator window. 1. In the main window, select a platform. 2. Click the Devices tab. The devices displayed are appropriate for the selected platform and its supported JSRs. 3. Click a device. Follow these steps to view the supported JSRs for a platform: 1. In the main window, open a project. 2. Select Project > Settings. 3. In the left pane, click API Selection. The toolkit displays the supported JSRs (see FIGURE 4-15).
Chapter 4
4-17
FIGURE 4-15
4.8.3
4-18
FIGURE 4-16
4. To use the API, check the box in front of the name. Click OK. The new API is added, as shown in FIGURE 4-17.
Chapter 4
4-19
FIGURE 4-17
To remove an API, check the Use box, and then click the Delete button.
4.8.4
4-20
FIGURE 4-18
4.8.5
Zoom In
The Zoom In feature displays a larger version of the device emulator screen. To zoom, double-click the device screen, or select MIDlet > Zoom In. An additional window opens displaying the device screen contents. See FIGURE 4-19.
Chapter 4
4-21
FIGURE 4-19
Zoom In Feature
4.8.6
4.8.6.1
QuickTime Plug-In
The Sprint Wireless Toolkit 3.2 uses a QuickTime plug-in to play additional media types and RTSP protocol.
Media Types
The following types can be played using QuickTime:
4-22
Rtsp Support
The Rtsp protocol is supported. When creating a Player you need to give the file's full path in the following format:
rtsp://<streaming server name>/<file name>
4.8.6.2
Chapter 4
4-23
4-24
CHAPTER
Monitoring Applications
The 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, and SMS. Tracing outputs low-level information to the console tab.
Note Monitoring features might slow down the execution of your application.
5.1
5-1
FIGURE 5-1
Now click the Run button to run your application. When you are finished, shut down the emulator. The profiler pops up with information about all the method calls in your application.
5-2
FIGURE 5-2
Method relationships are shown in a hierarchical list, the Call Graph. The right side of the profiler shows the execution time and number of calls for each method and its descendants.
Note The profiling values obtained from the emulator do not reflect actual values
on a real device.
Chapter 5
Monitoring Applications
5-3
5.1.1
5.1.2
Count is the number of calls. Cycles shows the amount of processor time spent in the method itself. %Cycles is the percentage of the total execution time that is spent in the method itself. Cycles with Children is the amount of time spent in the method and its called methods. %Cycles with Children shows the time spent in the method and its called methods as compared to the total execution time.
Click 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 the <root> node in the call graph.
5.1.3
5-4
To load a profiler session, choose File > Utilities.... Click Profiler and press Launch. When you select a file, the profiler window appears with all the session information.
5.2
global pointers data for all objects (classes, sizes, addresses and references) addresses for all roots names of all classes
The memory monitor slows down your application startup because every object created is recorded. 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. Because the memory monitor and the Java debugger use the same transport layer, the monitor and the debugger cannot be used at the same time.
To turn on the memory monitor, choose Edit > Preferences.... Click Monitor in the left pane. Check Enable Memory Monitor. The next time you run the emulator the Monty Memory Observe Tool displays a window similar to FIGURE 5-3.
Chapter 5
Monitoring Applications
5-5
FIGURE 5-3
To take a snapshot of the heap, click the Pause button on the bottom right. The virtual machine is suspended while the profiler collects the snapshot information. The memory panel is then repopulated and the Resume button becomes active. The memory monitor elements are as follows:
memory panel - At the top of the Monty window you see a grid of rectangles representing memory blocks. This is the memory panel. The key on the top right indicates the meaning of each graphical image. For example, in FIGURE 5-3, the majority of blocks are completely black, meaning they are at 100% utilization. Clicking a single block opens a dialog showing all the objects in that block. See FIGURE 5-4.
5-6
FIGURE 5-4
Objects Dialog
loaded classes - A list of loaded classes is displayed in the lower-left corner (see FIGURE 5-3). Choosing a class from the list causes the location of all objects in the class to be displayed in class objects list immediately to the right. class objects - The class objects list is populated when you select a class from the list of loaded classes. Select an object to see the class details. These include the address of the object, its type, and all references to and from the object. If the object is live, the Show path from the root button is enabled. Clicking this button opens the Path from the Root dialog (see FIGURE 5-5), which displays dependencies that prevent this object from being garbage collected.
Chapter 5
Monitoring Applications
5-7
FIGURE 5-5
statistics - At the bottom of the Monty Memory Observer tool (see FIGURE 5-3), click the Statistics button to see a table showing the information for each class (see FIGURE 5-6). Some objects are internal to the virtual machine. For each class, you see the Object number, size of all objects in the heap, the average size of the object, the percentage of the heap used by the selected class, the percentage of objects live in the selected class, and the percentage of objects that are in the old generation.
5-8
FIGURE 5-6
Heap Statistics
5.3
To turn on the network monitor, choose Edit > Preferences.... Click Monitor in the left pane. Check Enable Network Monitoring.
Next time you run the emulator, the network monitor window pops up.
Chapter 5
Monitoring Applications
5-9
FIGURE 5-7
When your application makes any type of network connection, information about the connection is captured and displayed. The figure shows HTTP requests and responses. The display on the left side shows a hierarchy of messages and message pieces. Click a message or a portion of a message to see details in the right side of the network monitor. Double-click on messages or message portions to expand or collapse them. 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.
5-10
5.3.1
Filtering Messages
Filters are useful for examining some subset of the total network traffic. Filter settings are specific to the network protocol used. Press the Filter Settings button to use the filter. Change the filter settings to suit your needs.
TABLE 5-1
Network Protocol
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. 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. 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. You can filter using the URL or header content. Filter on the URL or the message content. Enter text to match in either the connection string (URL) or content.
SMS
MMS
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.
5.3.2
Sorting Messages
To arrange the message tree in a particular order, click the Sort By combo box and choose a criteria.
Time. Messages are sorted in chronological order of time sent or received. URL. Messages are sorted by URL address. Multiple messages with the same address are sorted by time. Connection. Messages are sorted by communication connection. Messages using the same connection are sorted by time. This sort type enables you to see messages grouped by requests and their associated responses.
Chapter 5
Monitoring Applications
5-11
Sorting parameters are dependent on the message protocol you choose. For instance, sorting by time is not relevant for socket messages.
5.3.3
5.3.4
5.4
Tracing
To turn on tracing, select Edit > Preferences and select Monitor. In the Trace area, select the type(s) of tracing you want to see. Click OK. The trace information is displayed to the console tab whenever the emulator runs. To save the contents of the console, click the Save Console button.
5-12
CHAPTER
The GCD File Creator helps you create a General Content Descriptor (GCD) file. You must provide a GCD file if you are downloading to a Sprint device. The COMM Terminal utility uses a standard communication interface to receive and send input and output between a real mobile device and the toolkit. This utility is useful for debugging.
6.1
6-1
6.1.1
For information on Required attributes, see TABLE 6-1. For information on Optional attributes, consult TABLE 6-2. You can click another tab and continue to define properties. The User Defined tab starts with empty Name and Value columns. Click Add to define a new property. Fill in the Add Property form and click OK.
6-2
The new property is added. 5. Click Save As. Specify a file name and click save. All Required options are saved, even if there is no value specified. For the Optional and User Defined tabs, only the properties with values are saved. By default the file is saved in My Documents, but you can browse to any directory. 6. Once the GCD file is created, it can be signed as described in Section 7.4, Signing a GCD File on page 7-6.
6.1.2
6.1.3
Note that the Length column appears in both tables. Device manufacturers must support at least the number of characters shown in the Length column. For some devices the supported length might be greater than the value shown here. For example, Content-Name must support between one and 32 characters, but a manufacturer might choose to support 48 characters. In that case, an error is displayed if a user enters more than 48 characters.
Chapter 6
6-3
TABLE 6-1
GCD Attribute
Content-Type
(Implicit)
MIME type of the content. For Java applications, this is always application/java-archive A vendor-selected name for the content. Identifies the version of the content in major.minor[.micro] format Identifies the vendor (creator) of the content.
64
Must be a properly constructed MIME type per RFC 2045. If supported length is exceeded you see an error in the status report. Can be any text string. If supported length is exceeded you see an error in the status report. Proper Format = xx.xx[.xx]. (See the MIDP specification) If there is a format error you see an error in the status report. Can be any text string. If supported length is exceeded you see an error in the status report. Must be a valid relative URL to the JAR or other content-types or an absolute URL (beginning with http://, https://). If supported length is exceeded you see an error in the status report. If the URL is not found you see an error in the status report. Must be an integer value. If supported length is exceeded you see an error in the status report.
Content-Name
MIDlet-Name
32
Content-Version MIDlet-Version
Content-Vendor MIDlet-Vendor
32
Content-URL
MIDlet-Jar-URL The location from which the device can download the content
512
Content-Size
MIDlet-Jar-Size
6-4
TABLE 6-2
GCD Attribute
Content-ID
Content-ID
Identifier for the content so that it can be launched from outside the AMS. e.g. sprintpcs.com/1234 5 The URL to which the AMS MUST post the result code for the download and installation of the content. The delete notification URL is to make the vending machine aware of content which is no longer present on the device. Text describing the content
128
Content-Install-Notify
MIDlet-Install-Notify
512
Must be a valid absolute URL (http://, https://) If supported length is exceeded, the attribute is ignored Must be a valid absolute URL (http://, https://) If supported length is exceeded, the attribute is ignored Any text string. If supported length is exceeded, the field is truncated and processed as a valid field. Must be a valid absolute URL (http://, https://) If supported length is exceeded and/or the protocol invalid, the attribute is ignored.
Content-Delete-Notify
MIDlet-Delete-Notify
512
Content-Description
MIDlet-Description
128
Content-Info-URL
MIDlet-Info-URL
URL that a user MAY link to, to obtain more information about the content, including online help
512
Chapter 6
6-5
TABLE 6-2
GCD Attribute
Content-Icon-URL
MIDlet-Icon
URL of an icon to be used to represent the content. Note: in JAD, the MIDlet-icon attribute points to a file in the JAR, not an absolute URL. Icons are PNG files, with a maximum size of 15 x 15 pixels.
512
Content-Icon-URL Must be a valid absolute URL (beginning with http:// or https://) MIDlet-Icon URL Must reference image in JAR file. If supported length is exceeded and/or protocol invalid, the attribute must be ignored. Any text string. If supported length is exceeded, the attribute is ignored. If the attribute is anything but NO, the content is automatically locked and cannot be sent off the device. This is primarily used to initiate a launch request. If the parameter exceeds the number of characters, this value is truncated. This is primarily used to initiate a launch request. If the parameter exceeds the number of characters, this value is truncated.
Content-Folder
Content-Folder
Name of folder in the AMS where this download is stored. Case is ignored. If this attribute is NO (case insensitive), then applications on the device can allow the content to be sent off of the device. The character string indicated in this attribute is to be used for the Download Complete screen. The character string indicated in this attribute is to be used for the Download Complete screen.
16
Content-Forward-Lock
Content-Forward-Lock
Complete-Launch-Label
Complete-Launch-Label
32
Complete-Web-Label
Complete-Web-Label
32
6-6
TABLE 6-2
GCD Attribute
Complete-Description
Complete-Description
The character string indicated in this attribute is used to inform the user at the Download Complete Screen. Tells the AMS to automatically assign this content to a certain function. If present, the JAR must be authenticated by verifying the signer certificates and JAR signature.
128
Content-Assign
N/A
32
If the content type does not match the assignment you see an error. See MIDP 2.0 OTA specification Trusted MIDlet Suites
Content-RSA-SHA1
MIDlet-JAR-RSA-SHA1
176
2048
See MIDP 2.0 OTA specification Trusted MIDlet Suites TRUE (case insensitive) is the only valid entry. All other parameters or absence of this attribute means the download is not handled as Download and Play TRUE (case insensitive) is the only valid entry.
Video-Playback
N/A
Attribute is used to declare that this content is intended for immediate playback and is saved from the playback screen. Attribute is used to declare video content to be acceptable without user confirmation for Video Ringers.
Video-Ringer
N/A
Chapter 6
6-7
6.2
Note that the attribute names are in violation of the MIDP specification because they start with MIDlet. Consequently, you see the dialog in FIGURE 6-2 every time you add JAD attributes:
FIGURE 6-2
6-8
Note Remember to package and sign the application whenever you add or modify
its attributes.
.
JAD Attributes
Description Length Validity Criteria
MIDlet-Launch-Background
If the value is yes (case insensitive); when the MIDlet is launched, it must be launched to the background (not visible on UI). The splash screen MUST NOT be displayed.
If the parameters are not valid (or not present) according to the description, the attribute MUST be ignored and not assigned on device power on. If the midlet is not signed (e.g. MIDletJAR-RSA-SHA1 present and valid), then this attribute MUST be ignored. Multitasking VM ONLY (ignore attribute for single instance VM). If the parameters are not valid (or not present) according to the description, the attribute MUST be ignored and not assigned on device power on. If the midlet is not signed (e.g. MIDletJAR-RSA-SHA1 present and valid), then this attribute MUST be ignored. Multitasking VM ONLY (ignore attribute for single instance VM). Must be an integer value, If supported length is exceeded, descriptor is invalid If the amount declared exceeds the available heap space allowed for a single applications, then a 901 Insufficient Memory Heap is returned. Multitasking VM ONLY (ignore attribute for single instance VM). If the parameters are not valid according to the description (or not present), the AMS MUST ignore the attribute and allow application to exit. Multitasking VM ONLY (ignore attribute for single instance VM).
MIDlet-Launch-Power-On
If the value is yes (case insensitive), then the application MUST be launched when the device is powered on.
MIDlet-Heap-Size
Heap memory required by the MIDlet in order to execute. This value is considered a maximum value in bytes.
MIDlet-Background-No-Pause When an application is sent to the background, pauseApp is called. Adding this attribute with the value yes overwrites this functionality and keeps the application running in the background.
Chapter 6
6-9
6.3
COMM Terminal
The COMM Terminal utility uses a standard communication interface to receive and send input and output between a real mobile device and the toolkit. The mobile device must be connected to your PCs COM port with a serial cable or a USB cable. To aid in debugging, the COMM Terminal displays the System.out and System.err streams coming from a MIDlet running on the mobile device. You can use the terminal to write an instruction to the input stream. To launch the terminal from KToolbar, select File > Utilities. In the Utilities window, select COMM Terminal. The COMM Terminal opens (FIGURE 6-3).
FIGURE 6-3
COMM Terminal
Save Console - Saves the contents of the Terminal Log area to a text file of your choice. Close - Closes the terminal. Clear Console - Erases the Terminal Log area. Preferences - Preferences for the six COM connection parameters and values. This is a standard communication interface. The default settings are those most appropriate for Sprint devices (see FIGURE 6-4).
Edit
6-10
Available Ports: Data Bits: Baud Rate: Parity: Stop Bits: Flow Control:
FIGURE 6-4
COM1 (default) or COM2 5, 6, 7, or 8 (default). 300, 2400, 9600, 14400, 28800, 38400, 57600, 115200 (default) None (default), Even or Odd. 1 (default) or 2. 1.5 is not supported. None, Xon/Xoff Out, Hardware (default)
Terminal Log - Displays the output that comes from the mobile device. Input - Input entry field for sending data from the toolkit to the device. Enter data and click Send or press the enter key. Buttons
Connect - Initiates the communication between the device and the toolkit using the preferences that were last set. Disconnect - Terminates the communication between the device and the toolkit.
Chapter 6
6-11
Save Console - Save the contents of the Terminal Log area to a file. Clear Console - Erases the Terminal Log area.
6-12
CHAPTER
7.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.
7-1
In the toolkit, you can add these permission attributes to a project by clicking on the Settings... button. Select the Permissions icon. The MIDlet-Permissions box shows permissions which the MIDlet must possess, while the MIDlet-Permissions-Opt box contains permissions that are optional.
FIGURE 7-1
To add a permission to either box, Add and choose the permission you want to add. To remove a permission, highlight it and click Remove.
7-2
7.2
FIGURE 7-2
Security Preferences
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 default protection domain. The default is different for MSA and JTWI, as explained in Sections 7.2.1 and 7.2.2. If the MIDlet is signed, it is placed in the protection domain that is associated with the root certificate of the signing keys certificate chain. For example, suppose Respectable Software, a hypothetical company, wants to distribute a cryptographically signed MIDlet suite. Respectable Software buys a signing key pair from Super-Trustee, a hypothetical certificate authority. Using the signing key, Respectable Software signs the MIDlet suite and distributes their certificate with the MIDlet suite. When the MIDlet suite is installed on the emulator
Chapter 7
7-3
or on a device, the implementation verifies Respectables certificate using its own copy of Super-Trustees root certificate. Then it uses Respectables certificate to verify the signature on the MIDlet suite. Assuming everything checks out, the device or emulator installs the MIDlet suite into the protection domain that is associated with Super-Trustees root certificate, most likely identified_third_party. The toolkit provides tools to sign MIDlet suites, manage keys, and manage root certificates.
7.2.1
manufacturer - Intended for MIDlet suites whose credentials originate from the manufacturers root certificate. minimum - All permissions are denied to MIDlets in this domain. identified_third_party - Intended for MIDlets whose origins were determined using cryptographic certificates. Permissions are not granted automatically, but the user is prompted less often than for the unidentified_third_party domain. unidentified_third_party - Provides a high level of security for applications whose origins and authenticity cannot be determined. The user is prompted frequently when the application attempts a sensitive operation maximum - All permissions are granted to MIDlets in this domain.
When you press the Run button to run your application in the emulator, your code runs in the unidentified_third_party protection domain by default.
7.2.2
untrusted - Provides a high level of security for applications whose origins and authenticity cannot be determined. The user is prompted frequently when the application attempts a sensitive operation. trusted - All permissions are granted to MIDlets in this domain. minimum - All permissions are denied to MIDlets in this domain. maximum - All permissions are granted to MIDlets in this domain (equivalent to trusted.).
7-4
When you press the Run button to run your application in the emulator, your code runs in the untrusted protection domain by default.
7.3
FIGURE 7-3
Select the keystore you want to use from the Alias List and click the Sign Application ... button. The Sprint keystore will work in most cases. If you chose the Developer database, as described in Section 7.2, Setting Security Preferences on page 7-3, you should choose a keystore from the TCK or JDK.
Chapter 7
7-5
7.4
1. In the main window click the Sign button. The Sign Application window appears (see FIGURE 7-3). 2. Select Action > Sign Application. The Select JAD or GCD File window opens (FIGURE 7-4). Choose a GCD file and click the Sign Application button.
FIGURE 7-4
7-6
The Security Tool window notifies you that the file is signed. Click OK. Suppose you specify the following GCD file, test.gcd:
Content-Type: audio/wav Content-Name: test-wav Content-Version: Content-Vendor: Sun Content-URL: http://java.sun.com/products/java-media/mma/media/test-wav.wav Content-Size: 217
Chapter 7
7-7
7.5
Managing Keys
The MIDlet signing widow can also be used to manage keys and keystores.
7.5.1
7-8
FIGURE 7-5
After you select the file, you must select the key pair you want from the alias list. In FIGURE 7-6 the current keystore, mykeystore, has a key pair named respectable. A key pair named mykey is being imported from another keystore.
Chapter 7
7-9
FIGURE 7-6
As shown in FIGURE 7-6, each key pair in the keystore is identified by an alias displayed in the Alias List on the left. The toolkit prompts you to choose a protection domain, as explain in sections 7.2.1 and 7.2.2.
7.5.2
7-10
FIGURE 7-7
After you click Create, the toolkit prompts you to choose a protection domain, as explained in See Sections 7.2.1 and 7.2.2.
FIGURE 7-8
Chapter 7
7-11
The connection between the key pair you just created and a protection domain is established as follows:
The toolkit creates a self-signed root certificate using the key pair you just created. The root certificate is added to the emulators 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.
7.5.3
7-12
7.5.4
7.6
Managing Certificates
Youve already heard about the emulators list of root certificates. In this section, you learn how you can manage this list using the toolkit. Real devices have similar lists of root certificates, although they cannot usually be modified by the user. When you want to deploy your application on a real device, you must use signing keys issued by a certificate authority whose root certificate is present on the device. Otherwise, the device is unable to verify your application. While youre developing your application, the toolkits certificate management utility provides a convenient way to manipulate the emulators list of root certificates for testing purposes. Choose File > Utilities... from the KToolbar menu. Select Manage Certificates and press Launch to open up the certificate manager window.
Chapter 7
7-13
FIGURE 7-9
Each certificate is shown as a single line in the left part of the window, the Certificate List. When you select a certificate, its details are shown in the right part of the window. You also see the certificates associated protection domain.
7.6.1
7-14
7.6.2
Importing Certificates
You can import certificates either from certificate files or from Java SE keystore files. To import a certificate from a file, click Import Certificate... in the certificate manager window. After you locate the certificate file, choose which protection domain is associated with the certificate. To import a certificate from a Java SE 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.
7.6.3
Removing Certificates
To remove a certificate from the list, select the certificate and choose Action > Delete Selection.
Chapter 7
7-15
7-16
CHAPTER
8.1
8-1
FIGURE 8-1
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 has 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 +6269333333 for the Phone Number of Next Emulator and +5555555555 for the First Assigned Phone Number. If you launch four emulator instances, their numbers are +6269333333, +5555555555, +5555555556, and +55555555557.
8.2
8-2
If youd 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.
8.3
Chapter 8
8-3
FIGURE 8-2
8.3.1
8-4
FIGURE 8-3
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.
8.3.2
Chapter 8
8-5
FIGURE 8-4
Selecting recipients is the same as for sending text SMS messages. You can type in the path of a file directly, or click Browse... to open up a file chooser.
8.3.3
8-6
FIGURE 8-5
To add media files to the message, click the Parts tab. Click Add to add a part to the message. To remove a part, select it and click Remove.
FIGURE 8-6
Chapter 8
8-7
8.4
8-8
CHAPTER
9.1
Third Generation Partnership Project (3GPP) for audio Third Generation Partnership Project 2 (3GP2P) for audio Advanced Audio Coding (ACC) Adaptive Multi-Rate (AMR) Musical Instrument Digital Interface (MIDI) files MPEG Audio Layer 3 (MP3)
9-1
audio/qcelp audio/sp-midi audio/vnd.qcelp audio/x-tone-seq audio/x-wav image/gif video/3gpp video/3gpp2 video/mp4 video/mpeg video/quicktime video/vnd.sun.rgb565 video/x-h264
Qualcomm PureVoice Scalable Polyphony MIDI Qualcomm PureVoice MIDP 2.0 tone sequence WAV PCM sampled audio GIF 89a (animated GIF) Third Generation Partnership Project (3GPP) for video Third Generation Partnership Project 2 (3GP2P) for video MPEG-4 Moving Picture Experts Group) MPEG video QuickTime Video capture MPEG-4 Part 10
The Sprint Wireless Toolkit 3.2 supports additional media types. See Section 4.8.6, Additional Media Types on page 4-22.
9.2
Media Capture
The toolkit emulator supports audio and video capture. Audio capture is supported by using the capture capabilities of the system upon which the emulator runs. Video capture is supported by simulating a camera input. Consult the mmademo example application for details and source code that demonstrates how to capture audio and video.
9-2
9.3
Well-Behaved MIDlets
MIDlets have a life cycle that is defined in the MIDP specification. MIDlets can be paused by events such as incoming phone calls. A well-behaved MIDlet releases important device resources when it is paused and reallocates or restarts those resources when the MIDlet is resumed. In the MMAPI arena, any Players that are rendering content should be stopped when a MIDlet is paused. The toolkit prints 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 A for details. The warning message is printed once only for each running emulator.
Chapter 9
9-3
9-4
CHAPTER
10
The Scalable 2D Vector Graphics API for J2ME, JSR 226, support rendering sophisticated and interactive 2D content. The Mobile 3D Graphics API for J2ME, JSR 184, provides 3D graphics capabilities with a low-level API and a high-level scene graph API. This chapter provides a brief overview and general guidelines for working with JSR 184.
10.1
BeatWare Mobile Designer (http://www.beatware.com/products/md_golive.html) Ikivo Animator (http://www.ikivo.com/animator/) Adobe Illustrator CS2 (http://www.adobe.com/products/illustrator/main.html)
10-1
10.2
10.2.1
Immediate Mode
Immediate mode is appropriate for applications that generate 3D graphics content algorithmically, like scientific visualizations or statistical graphs. The application creates 3D objects and manipulates them directly. For an example of immediate mode, see the Life3D MIDlet in the Demo3D example application.
10.2.2
Retained Mode
Most applications, particularly games, use the retained mode or scene graph API. In this approach, a graphic designer or artist uses 3D modeling software to create a scene graph. The scene graph is saved in the JSR 184 file format. The scene graph file is bundled with the application. At runtime, the application uses the scene graph API to load and display the file.
10-2
Applications can manipulate parts of a loaded scene graph to animate characters or create other effects. The basic strategy is to do as much work as possible in the modeling software. At runtime, the application can grab and manipulate parts of the scene graph, which can also include paths for animation or other effects. For an example of retained mode, see the retainedmode MIDlet in the Demo3D example application.
10.2.3
10.2.4
Chapter 10
10-3
10-4
CHAPTER
11
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 toolkit implements the FileConnection and PIM APIs.
11.1
11-1
Note If multiple instances of the same emulator skin run simultaneously, the
toolkit generates unique file paths for each one. For example, a second instance of Samsung940 might have a file system path name of toolkit\appdb\ temp.SamsungA940.1145262863406\filesystem. Each subdirectory of filesystem is called a root. The toolkit provides a mechanism for managing roots. While the emulator is running, choose MIDlet > External events from the emulator windows menu. You see a utility window for adding and removing roots (FIGURE 11-1).
FIGURE 11-1
The mounted roots and their contents are available to applications using the FileConnection API. To add a new root directory, click Mount New... Fill in a name for the directory and click OK. To make a directory inaccessible to the FileConnection API, select it in the list and click Unmount.
11-2
11.2
Chapter 11
11-3
11-4
CHAPTER
12
12.1
12.2
12-1
FIGURE 12-1
Bluetooth Preferences
12.2.1
12.2.2
12-2
12.2.3
BCC Properties
Description
Encryption
This property determines whether connection encryption is supported (on) or not (off). In addition, the force settings means all connections must be encrypted. See the documentation for RemoteDevices encrypt() method for details. This is similar to the Encryption property. See RemoteDevices authorize() method. This is similar to Encryption and Authorization. See RemoteDevices authenticate() method.
Authorization Authentication
Chapter 12
12-3
12-4
CHAPTER
13
13-1
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. Press OK to generate the stub files.
13-2
CHAPTER
14
14.1
14-1
FIGURE 14-1
In the Location area of the tab, you can fill in values for the latitude, longitude,
14-2
altitude, speed, and course. Applications that use the Location API can retrieve these values as the location of the emulator. For more elaborate testing, you can set up a location script that describes motion over time. Location scripts are XML files consisting of a list of locations, called waypoints, and associated times. The toolkit determines the current location of the emulator by interpolating between the points in the location script. Here, for example, is a simple location script that specifies a starting point (time="0") and moves to a new point in ten seconds:
<waypoints> <waypoint time="0" latitude="14" longitude="50" altitude="310" /> <waypoint time="10000" latitude="14.5" longitude="50.1" altitude="215" /> </waypoints>
The altitude measurement is in meters, and the time values are in milliseconds. Use a text editor to create your location script. You can load it into the external event window by pressing on the Browse... button next to the Script field. Immediately below are controls for playing, pausing, stopping, and moving to the beginning and end of the script. You can also drag the time slider to a particular point. Some devices are also capable of measuring their orientation. To make this kind of information available to your application, change the State field in the Orientation box to Supported and fill in values for azimuth, pitch, and roll. The Magnetic Orientation checkbox indicates whether the azimuth and pitch measurements are relative to the Earths magnetic field or relative to true north and gravity. To test how your application handles unexpected conditions, try changing the State field in the Location Provider box to Temporarily Unavailable or Out of Service. When your application attempts to retrieve the emulators location, an exception is thrown and you can see how well your application responds.
14.2
Chapter 14
14-3
FIGURE 14-2
The fields in the Location tab allow you to specify the properties of the toolkits built-in location provider. The properties you specify in the preferences correspond to the Criteria class applications use to request a location provider.
14.3
Setting Up Landmarks
The toolkit emulator includes a landmark store system, just like many real devices. A landmark store is a collection of places with associated names and other information. To manage landmark stores, choose File > Utilities from the menu, select Manage Landmarks, and press Launch.
14-4
FIGURE 14-3
The landmark manager shows the content of a single landmark store. There is, at a minimum, a single landmark store called default store, which is required by JSR 179. Use the Landmark stores: combo box at the top of the window to select a different landmark store or create a new one. You can add or remove landmark stores by clicking on the Manage Landmark Stores button. Landmark stores cannot be renamed. Landmarks can be associated with categories, which are specific to a landmark store. The categories for the current landmark store are shown in the left pane of the window. You can add or remove categories using the buttons at the bottom of the list. Check off one or more of the categories if you would like to see only the matching landmarks. You can also check off no category set to see landmarks with no associated categories. The right pane of the landmark manager lists the landmarks in the current landmark store. Click a landmark to see its details listed in the bottom part of the right pane.
Chapter 14
14-5
To add a new landmark, click Add and fill in the fields as appropriate. Click Edit to change the currently selected landmark. Finally, press Remove to remove the currently selected landmark.
FIGURE 14-4
You can also use the Assign Categories in the main window to specify the categories for a landmark.
14-6
CHAPTER
15
Using SATSA
The Security and Trust Services APIs (SATSA) provide smart card access and cryptographic capabilities to applications running on small devices. The SATSA specification defines four distinct APIs:
SATSA-APDU allows applications to communicate with smart card applications using a low-level protocol. SATSA-JCRMI provides an alternate method for communicating with smart card applications using a remote object protocol. SATSA-PKI allows applications to use a smart card to digitally sign data and manage user certificates. SATSA-CRYPTO is a general-purpose cryptographic API that supports message digests, digital signatures, and ciphers.
The four SATSA APIs are defined by JSR 177, the Security and Trust Services APIs specification. The Sprint Wireless Toolkit 3.2 (the toolkit) emulator fully supports SATSA. This chapter describes how you can use the toolkit to work with SATSA in your own applications. For a more general introduction to SATSA and the fun that small devices can have with smart cards, see the SATSA Developers Guide: http://java.sun.com/j2me/docs/satsa-dg/ The toolkit includes the Java Card Platform Simulator, which you can use to simulate smart cards in the toolkit emulators slots. The Java Card Platform Simulator is toolkit\bin\cref.exe and hereafter it is referred to as simply cref. If you need to develop your own Java Card applications, you want to download the Java Card Development Kit, available here: http://java.sun.com/products/javacard/
15-1
15.1
FIGURE 15-1
15.2
15-2
3. When a SATSA application attempts to communicate with a smart card, it uses a socket connection to communicate with cref. Its important, therefore, to make sure that you start cref with the same port number as one of the slot port numbers you specified in the toolkit preferences. For example, you could run cref on port 9025 with a prebuilt memory image using a command line like this:
cref -p 9025 -i memory_image.eeprom
The toolkit includes a demonstration application, Mohair, which illustrates how to use SATSA. For detailed instructions on running Mohair, see Appendix A.
15.3
15.3.1
Chapter 15
Using SATSA
15-3
15.3.2
The acf record is an Access Control File. The AID after acf identifies the application. A missing AID indicates that the entry applies to all applications. The acf record can contain ace records. If there are no ace records, access to an application is restricted by this acf.
15-4
The ace record is an Access Control Entry. It can contain root, apdu, jcrmi, pin_apdu and pin_jcrmi records. The root record contains one CA name. If the MIDlet suite was authorized using a certificate issued by this CA, this ace grants access to this MIDlet. A missing root field indicates that the ace applies to all identified parties. One principal is described by one line. This line must contain only the word root and the principal name. For example:
root CN=thehost;OU=JCT;O=dummy CA;L=Santa Clara;ST=CA;C=US
The apdu or jcrmi record describes an APDU or JCRMI permission. A missing permission record indicates that all operations are allowed. An APDU permission contains one or more sequences of 8 hexadecimal values, separated by blanks. The first four bytes describe the APDU command and the other four bytes are the mask. For example:
apdu { 0 20 80 20 }
0 82 0 20 0 0 ff ff
0 82 0 0
The JCRMI permission contains information about the hash modifier (optional), class list, and method list (optional). If the list of methods is empty, an application is allowed to invoke all the remote methods of interfaces in the list of classes. For example:
jcrmi { classes { com.sun.javacard.samples.RMIDemo.Purse } hashModifier zzz methods { debit(S)V setAccountNumber([B)V getAccountNumber()[B } }
All the numbers are hexadecimal. Tabulation, blank, CR and LF symbols are used as separators. Separators can be omitted before and after symbols { and }. The pin_apdu and pin_jcrmi records contain information necessary for PIN entry methods, which is the PIN identifier and APDU command headers, or remote method names.
Chapter 15
Using SATSA
15-5
15.3.3
15-6
change 4 3 2 2 disable 1 1 1 3 enable 5 5 5 4 unblock 7 7 7 5 } } } acf a0 0 0 0 62 3 1 c 8 1 { ace { root CN=thehost;OU=JCT;O=dummy CA;L=Santa Clara;ST=CA;C=US jcrmi { classes { com.sun.javacard.samples.RMIDemo.Purse } hashModifier xxx methods { setAccountNumber([B)V getBalance()S credit(S)V } } } ace { jcrmi { classes { com.sun.javacard.samples.RMIDemo.Purse } methods { debit(S)V getAccountNumber()[B } } } } acf a0 00 00 00 62 03 01 0c 02 01 { ace { root CN=thehost;OU=JCT;O=dummy CA;L=Santa Clara;ST=CA;C=US apdu { 0 20 0 82 0 20 0 82 80 20 0 0 ff ff 0 0 } apdu { 80 22 0 0 ff ff 0 0 } } } acf a0 00 00 00 62 03 01 0c 02 01 {
Chapter 15
Using SATSA
15-7
15-8
Chapter 15
Using SATSA
15-9
CHAPTER
16
Using SIP
The Sprint Wireless Toolkit 3.2 supports the SIP API for J2ME (JSR 180) with a proxy server, registrar, and network monitor support. Session Initiation Protocol (SIP) is defined by RFC 3261, available at http://www.ietf.org/rfc/rfc3261.txt. SIP provides a standard way for applications to set up communications. The application determines what communication actually takes place. SIP can be used to set up instant messaging, text chat, voice chat, video conferencing, or other types of sessions.
16.1
16-1
The Sprint Wireless Toolkit 3.2 includes a very simple SIP proxy and registrar server that you can use for testing applications that use the SIP API. You can also configure the toolkit to use an external proxy server and registrar server.
16.2
SIP Settings
To adjust settings for the Sprint Wireless Toolkit 3.2 SIP environment, choose Edit > Preferences from the KToolbar menu and click SIP.
FIGURE 16-1
SIP Settings
Display name and Address set the system properties sip.display.name and sip.address, respectively. Applications can use these system properties as a standard way to retrieve the identity associated with the device.
16.3
16-2
FIGURE 16-2
To start the server, click Start. To stop the server, click Stop. While the server is running, the top left pane shows all users known to the registrar. Click a user name to see details about the user in the top right pane. The bottom pane of the window is a console that shows SIP messages that are received and sent by the proxy.
Chapter 16
Using SIP
16-3
You can adjust the server options when the server is not running. Click Stop to hals the server. Click the Options button to see the Options window. On the Proxy tab, you can set the IP address and ports upon which the server listens for incoming messages. Click Add to specify more ports and their types. Select a port and click Remove to take away a listening port. Check Use Authentication to force connecting clients to authenticate themselves to the server. The scheme used is digest authentication, which is described in section 22.4 of RFC 3261. SIPs digest authentication is nearly identical to HTTP digest authentication.
FIGURE 16-3
On the Registrar tab, you can set up the users and domains known to the registrar. The top list contains SIP users that are automatically registered when the SIP server is started. You can add a new user, edit an existing user, or remove a user. In addition, you can adjust the list of domains managed by this registrar. Press Add to add a domain, Edit to edit an existing domain name, or Remove to remove a domain.
16-4
FIGURE 16-4
Chapter 16
Using SIP
16-5
16-6
CHAPTER
17
17.1
17-1
FIGURE 17-1
Payment Settings
The fields and values are explained fully in JSR 229, the Payment API specification.
17-2
The General box contains information about the Payment API version in use and where to find payment updates. For testing, you can specify a localhost URL (as shown in the screen shot) that retrieves an update file directly from your project directory. The Debug box contains options that are useful during application testing. Each option is explained in the Payment API specification. The Features box lists the features your application can charge. These features correspond to the pricing information that is listed for each provider. You can modify the list of features by using the Add and Remove buttons. The Providers box lists specific payment providers that can be used for this application. When the time comes to make a payment, the emulator (or device) matches one of its available payment adapters to one of the providers listed for the application. You can modify the list of providers with the Add, Edit, and Remove buttons. If you add or edit a provider, the following window appears.
FIGURE 17-2
These fields are also described fully in the Payment API specification. The Price Info box contains one line for each defined payment feature. To edit a value for a price tag, double click the corresponding cell in the Value column.
Chapter 17
17-3
17.2
17.3
Payment Preferences
You can adjust the Payment API settings for the toolkit by choosing Edit > Preferences from the KToolbar menu and clicking Payment.
17-4
FIGURE 17-3
The Mobile Country Code (MCC) and Mobile Network Code (MNC) are used in conjunction with PPSMS payment providers. Taken together, the MCC and MNC identify the wireless carrier of a device. At payment time, the MCC and MNC are used to find a matching provider from the list of providers in the project settings. Because the emulator is not a real device, you can simulate a carrier by filling in appropriate values for MCC and MNC. Consult the Payment API specification for more details. Past Transactions Limit determines how many previous transactions are recorded in the emulator. This affects the length of the list shown in the external event window, described below, as well as the number of past transactions that can be retrieved by the application itself. Finally, Console Phone Number determines the simulated phone number of the payment console, which is described later.
17.4
Chapter 17
17-5
FIGURE 17-4
Click Refresh to update the list after making more payments. Select a transaction and click Details to see all the details in a separate window.
17-6
The external events window only shows transactions that have been made while the emulator is running via OTA. Although it is possible to complete transactions without using OTA, such transactions are not shown. For the most realistic simulation of payments, always use Run via OTA to test applications.
17.5
Monitoring Payments
The Sprint Wireless Toolkit 3.2 provides a payment console that makes it easy to see payments passing through the example payment adapter.
FIGURE 17-5
Payment Console
In addition, you can view transactions using the network monitor. Credit card transactions are conducted using HTTPS, while PPSMS transactions use SMS. For a full description of the network monitor, see Chapter 5.
Chapter 17
17-7
17-8
CHAPTER
18
18.1
18.2
18-1
FIGURE 18-1
Resource Manager
First, choose your project from the Projects menu. All the resources for the selected project are shown in the rest of the window. If this is your first time looking at the resource manager, look at the resources for the i18nDemo demonstration application, which contains lots of interesting resources. You can click + symbols to expand directories or - symbols to collapse them. Nearly all other operations are available by right-clicking directories or resource files. The top pane of the window shows the hierarchy of resource files in the application, while the bottom pane shows the contents of a resource file. In FIGURE 18-1, the contents of the top-level common resource file are being displayed.
18-2
18.3
18.4
18.5
Chapter 18
18-3
To add an image or another type of data, click Add and select Add binary resource. You can browse to whatever file you want to add. Again, you can change the identifier if you wish. Click OK to add the resource.
FIGURE 18-2
To edit a resource, double-click it. You can type a new value for a string resource. If you double-click file resources, you can choose another file.
18-4
CHAPTER
19
19.1
External Canvas
The Sprint 2.0 extension includes an API that allows applications to display to either the main screen or a secondary screen. This is relevant for flip devices. The secondary screen is also referred to as the external screen or the external canvas. The Sprint API class com.sprintpcs.lcdui.ExternalCanvas allows MIDlets to draw to a secondary Liquid Crystal Display (LCD) on the device. The setLCD method controls the display as follows:
Display to primary screen: Display to secondary screen: Choose the screen based on device state (closed or open):
19.2
Sprint Location
The Sprint 2.1 extension includes an API that allows applications to get the location of the device's BSC (Base Station Controller), which supplies Radio Frequency (RF) services to the device. The specification also includes an API that allows applications to get location information from a server that supplies GPS services to some of Sprint's devices. The class com.sprintpcs.util.Location is only available with
19-1
the 2.1 API. It enables a MIDlet to perform specific Location logic beyond the JSR179 Location API: http://www.jcp.org/en/jsr/detail?id=179. The Sprint Location API is not fully implemented because the GPS server is not simulated. The getBSCLatitude method returns the BSC latitude value and the getBSCLongitude returns the BSC Longitude value. The following steps describe how to edit the values of BSC Latitude and BSC Longitude to control the values that these methods return. 1. Run your project. 2. In the emulator window, select Midlet > External Events. 3. In the External Event Generator window (FIGURE 19-1), click the Location tab and find the Sprint Location area at the bottom of the window. 4. Edit the values of BSCLatitude and BSCLongitude properties.
19-2
FIGURE 19-1
Location Panel
Chapter 19
19-3
19.3
Muglet
The Sprint com.sprintpcs.util.Muglet class that belongs to the Sprint 1.0 extension simplifies content handling. With the Muglet mechanism, a MIDlet can use content without knowing its format and without specifying the midlet required to process that format. When the content is used, the Muglet mechanism checks the content type and activates the appropriate midlet. To support the Muglet mechanism, the Toolkit maintains the Generic Content Descriptor (GCD) table. Use this table to list content you want to make available to your applications. The GCD table lists the following information for each content item:
Unique ID Mime type: The file type. For example: media\x-wav URL: The exact location of the file. It could be an HTTP URL, or it can be located in a MIDlets JAR.
Follow these steps to edit the GCD table: 1. Select File > Utilities. See FIGURE 19-2. 2. Select GCD Manager and click the Launch button. The GCD Manager window opens (FIGURE 19-3).
19-4
FIGURE 19-2
Utilities Window
Chapter 19
19-5
FIGURE 19-3
GCD Table
3. To add a resource, click Add. An empty row is added to the table. 4. Edit each field. See FIGURE 19-3 for an example.
Note Muglet-related MIDlets must be run via OTA. See Section A.18, Muglet
Demo on page A-43. The Muglet content handling process has two participants: the calling MIDlet and the handling MIDlet.
The calling MIDlet needs a resource but doesn't have the ability to handle it. It redirects the resource. The implementation launches the handling midlet to handle the resource.
19.3.1
19-6
If the content file name is passed without the handling MIDlet, the implementation finds and activates a MIDlet that can handle the file type.
19.4
System
The Sprint 2.0 specification includes an API that supports receiving notifications and setting different system properties. This functionality is provided by the com.sprintpcs.util.System class and the com.sprintpcs.util.SystemEventListener interface. To be notified whenever properties change, an application should implement SystemEventListener and implement the systemEvent(java.lang.String property, java.lang.String value) method. The toolkit allows the developer to edit property values. 1. Run your project. 2. In the emulator window, select Midlet menu > External Events. 3. Click the Sprint System States tab. The properties panel (FIGURE 19-4) has two tabs: Protected Properties and Non-Protected Properties. Only non-protected properties can be edited.
Chapter 19
19-7
The Non-Protected Properties tab (FIGURE 19-4) has separate areas for 2.0, 2.1, and 2.2 version properties. Selecting 2.0 excludes 2.1 and 2.2. Selecting 2.0 includes 2.1, and selecting 2.2 includes all properties. For descriptions of each property, see the Sprint 2.1 and 2.2 Extenstions documentation in the install-dir\docs\api directory.
FIGURE 19-4
Non-Protected Properties
19-8
The System API also activates the volume monitoring mechanism when System.promptMasterVolume is called, as shown in FIGURE 19-5.
FIGURE 19-5
Master Volume
Chapter 19
19-9
19-10
APPENDIX
Application Demonstrations
This appendix describes the application demonstrations that are bundled with the Sprint Wireless Toolkit 3.2 (the toolkit).
A.1
Overview
The toolkit includes demonstration applications that highlight some of the technologies and APIs that are supported by the emulator. The goal of these demonstrations is to give you a glimpse of the API features of the emulator and the enhancements throughout the toolkit.
TABLE A-1 lists all the demonstration applications that are included in this release.
Most demonstration applications are simple to run. Section A.2, General Instructions on page A-4 contains instructions for running most demonstrations. Demonstrations that have additional documentation are linked in TABLE A-1. If there is no link, the demonstration is simple (or has its own instructions) and the general instructions are sufficient. The source code for every demonstration application is available in the toolkit\apps directory. Subdirectories contain projects, and each project has a src directory that contains Java programming language source code. For example, if the toolkit is installed in C:\SPRINT_WTK_32, the source code for the SMS sender MIDlet (example.sms.SMSSend) in WMADemo is contained in C:\SPRINT_WTK_32\apps\ WMADemo\src\example\sms\SMSSend.java.
A-1
TABLE A-1
Application Demonstrations
APIs Description Special Instructions
Demonstration
Shows 3D audio, reverberation, image processing, and camera control. Demonstrates audio capabilities, including mixing and playing audio with an animation. Demonstrates device discovery and data exchange using Bluetooth. A content viewer which also makes uses of MediaHandler. Shows a city map that displays landmarks based on the current location. Demonstrates how to write or read data to and from a COMM console or device.
A.3
DebugApp
A.7
Demo3D
JSR 184 Mobile 3D Graphics MIDP 2.0 CLDC 1.1 MIDP 2.0 JSR 180 SIP
Contains MIDlets that demonstrate how to use 3D graphics, both immediate mode and retained mode.
A.8
Includes various examples: animation, A.9 color, networking, finance, and others. Simple floating point calculator. Includes TilePuzzle, WormGame, and PushPuzzle. Demonstrates setting up a chat using SIP and a SIP server. A simple Hello World MIDlet.
A.10
JSR 238 Mobile Internationalization API JSR 229 Payment API Web services
Includes string sorting, number formatting, and a phrase translator. A game that uses the Payment API for buying extra lives or levels.
A.11
JBricks JSR172Demo
A.12
Demonstrates how to use the JSR 172 A.13 API to connect to a web service from a MIDlet.
A-2
TABLE A-1
Demonstration
When a key is pressed, displays the corresponding event. Demonstrates portrait and landscape display for LX260. Demonstrates MMAPI features, including tone sequences, MIDI playback, sampled audio playback, and video.
MP4Player
Sprint
Demonstrates that MP4 files can be A.17 played on an external screen for Sprint 2.0 extensions. Demonstrates MIDlet capabilities for Sprint 1.0 extension. Demonstrates Multitasking VM settings. Demonstrates Multitasking VM settings. Demonstrates Multitasking VM settings. Shows how to use datagrams and serial connections. Demonstrates transferring data using OBEX over IrDA. Shows how to manipulate contacts, calendar items, and to-do items. Demonstrates accessing local files. Demonstrates a variety of image formats. Demonstrates RAZR2 touch sensitive button support.
A.23 A.24 A.25 A.18 A.19 A.19 A.19 A.20 A.21 A.22
Sprint Sprint Sprint Sprint MIDP 2.0 JSR 82 OBEX JSR 75 PIM and FileConnection MIDP 2.0
Demonstrates RecordStore, as defined in the MIDP 1.0 and 2.0 APIs. Demonstrates communication with a smart card and other features of SATSA. Shows how to use SATSA-JCRMI.
SATSAJCRMIDemo
A.26
Appendix A
Application Demonstrations
A-3
TABLE A-1
Demonstration
JSR 180 SIP Sprint JSR 226 SVG API JSR 226 SVG API MIDP 2.0
Uses SIP to communicate between two A.27 devices. Includes External Canvas demo, SystemStates demo, and Media demo. Demonstrates a contact list displayed with different skins. Shows different techniques for rendering SVG Showcases the breadth of MIDP 2.0's user interface capabilities Java virtual keypad for the Samsung UpStage device
A.28 A.29 A.30 A.31 A.32 A.33
WMA 2.0
A.2
General Instructions
Most of the demonstration applications can be run then launched with no special preparation. Some demonstrations, however, require changes to the toolkit preferences or settings. This section describes the general procedure. The first step is to run the toolkit. Go to the Microsoft Windows Start menu and choose Start > Programs > Sprint Wireless Toolkit 3.2 - Powered by Java Technology > KToolbar. The KToolbar window appears:
A-4
FIGURE A-1
KToolbar
Click the Open Project button to open a demonstration application. A list of all the available applications appears.
Appendix A
Application Demonstrations
A-5
FIGURE A-2
Select a project and click the Open Project button in the dialog. Once the application is open, press the Run button. The device emulator window opens with the demo application running. If there is a menu of MIDlets, use the navigation arrows to choose an item, then choose SELECT. As the demonstration progresses you might need to press one of the soft keys below the screen on the left or right side. You use soft keys to launch an application, open a menu, exit, or perform some other action.
A-6
Some demonstrations require specific setup and instructions. For example, if an example uses web services and you are behind a firewall, you must configure the emulators proxy server settings or the demo fails. Choose Edit > Preferences from the KToolbar menu, then select Network Configuration. Check Use proxy server. Fill in the proxy server address field and the port number. Read each demonstration description for more operating instructions. Sometimes a menu has numbered items. To choose an item number, type it on your keyboard or click the number on the emulator keypad. Some demonstrations require other setup and instructions. Check the full list to see if there are specific instructions for a demonstration.
A.3
Moving Helicopter - Simulates a helicopter flying around a stationary observer (the red dot is the helicopter and the blue dot is the observer). Use headphones for best results. From the soft menu, you can control the following effects:
Appendix A Application Demonstrations A-7
1. Volume. 2. Location Settings. The screen width determines how far the helicopter can range and the flight altitude affects the level of sound from the helicopter. 3. Spectator Orientation. A radio button list describes the position of the observer. If you have fallen on your right side, you should only hear through your left ear, while the opposite is true if you fall on your left side. For the other options the sound difference is subtle. 4. Distance Attenuation setting. For the minimum attenuation distance, a high number makes the volume louder overall as the helicopter advances and retreats. For the factor determining the speed of the sound attenuation, a high number causes the sound to fade more quickly. The maximum attenuation distance is the limit of the observers ability to distinguish sound. If Mute beyond Maximum Distance is checked, the observer hears nothing when the helicopter is out of range. For example, if the screen width is 30 meters, and the maximum attenuation distance is 12 meters, the sound will disappear as the helicopter nears the edge of the screen. Options 1, 2 and 4 use interactive gauges like those shown in FIGURE A-4. To change a setting, navigate left or right to highlight a + or - control. With the + or - highlighted, press select to perform the action. The number of bars in the gauge increases or decreases, and the values change. If you cant see all the settings, navigate down to scroll the screen.
FIGURE A-4
A-8
A.4
Bluetooth Demo
This application contains MIDlets that demonstrate the use of JSR 82s Bluetooth API. The project BluetoothDemo shows how images can be transferred between devices using Bluetooth. You must run two instances of the emulator to see how this demonstration works. In the first emulator, launch Bluetooth Demo, then choose Server. The emulator asks you if you want to allow a Bluetooth connection. Choose Yes. The server starts and displays a list of images. At the beginning, none of the images are available on the Bluetooth network. To make images available, select them and from the menu choose Publish image (or type or click 1). The icon color changes from purple to green, indicating it is published.
FIGURE A-5
On the second emulator, launch Bluetooth Demo, then select Client. The MIDlet tells you its ready to search for images. Click the Find soft button. The MIDlet finds 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.
If you are running the demonstration in a trusted protection domain, the image is transferred using simulated Bluetooth and is shown on the client emulator. If you are not running in a trusted protection domain, the first emulator (the server) displays a prompt asking if you want to authorize the connection from the client. Choose Yes. The image is displayed in the client emulator.
Appendix A
Application Demonstrations
A-9
FIGURE A-6
A.5
CHAPIDemo
CHAPIDemo is a content browser. It maintains a list of favorites and enables you to select and view various kinds of content. This demonstration uses the content handler registry, so you cannot see all of its features when you use the Run button. Instead, use Project > Run via OTA to install the application into the emulator. If you dont know how to do this, read about it in Section 2.3.2, Install on page 2-10. After you install CHAPIDemo, it appears in the application list as Text Viewer. It is a MIDlet that is a content handler for plain text. Select Text Viewer and choose Launch from the soft button menu. A list of favorite links appears.
A-10
FIGURE A-7
Use the navigation keys to highlight CHAPIDemo then press SELECT on the emulator. The application asks if it is OK to use airtime. Press the Yes soft button. A list of various types of content appears (FIGURE A-8).
FIGURE A-8
Content List
Try selecting one of the PNG files first. Use the arrows to highlight the link, then press SELECT to view the file. Using CHAPI, the ImageViewer MIDlet is launched and displays the content.
Appendix A
Application Demonstrations
A-11
FIGURE A-9
The other types of content require another content handler MIDlet suite, MediaHandler. To install this suite from CHAPIDemo, select the http:handlers/MediaHandler.jad link (from the list shown in FIGURE A-8). The AMS is invoked and leads you through the installation. After the MIDlet suite is installed, you can view the other types of content listed in Text Viewer. For example, select http:video/test-mpeg.mpg to see a series of images including the one shown in FIGURE A-10.
FIGURE A-10
To view the content handler settings for the TextViewer and ImageViewer MIDlets, click Settings in KToolbar, then click the Content Handlers icon. You might also wish to examine the MediaHandler project.
A-12
A.6
CityGuide
CityGuide shows how you can use the Location API. It shows your current position superimposed on a city map. As you move around the city, interesting landmarks are highlighted and identified. Because location prompts occur frequently, it is best to run this demonstration in trusted or maximum mode. In Ktoolbar, select Edit > Preferences, then select Security. Choose maximum for the Security domain. Open and run the CityGuide project. In the emulator, launch the CityGuide MIDlet. Click Next to view the map page.
FIGURE A-11
Choose MIDlet > External events from the emulator window menu. On the location tab (see FIGURE A-11), click the browse button and select the file toolkit\apps\ CityGuide\citywalk.xml.
Appendix A
Application Demonstrations
A-13
FIGURE A-12
A-14
The player buttons at the bottom of the window are now active. Press the green play button (right-pointing triangle) to run the script. The display shows four types of landmarks: restaurants, museums, shops, and theaters. Open the soft menu and choose the Settings command to adjust the landmark display. Use the navigation keys to highlight a category, then use SELECT to check or uncheck an item. When you are near a landmark (shown highlighted on the map), open the soft menu and choose the Detail command to see more information. See Chapter 14 for more details on location scripts.
A.7
DebugApp
DebugApps demonstrates how to transmit the System.out and System.err streams from a MIDlet running on a real device to the toolkit running on a PC. For this example we use two PCs (instead of a PC and a device). We call them PC1 and PC2.
PC1 is running the toolkit and the emulator. PC2 represents the real device running the MIDlet. This demo document features screen shots showing the toolkits COMM terminal, but there is no requirement to install the toolkit on PC2. All that is required is a console, such as HyperTerm.
1. Use a serial cable to connect two PCs on the same COM port. For example, run a serial cable between COM1 on PC1 and COM1 on PC2. 2. On PC2, configure the console for this demo. The demo uses the following fixed parameter values, so set your console preferences to match:
baudrate parity stopbits databits flow control 115200 none 1 8 hardware
3. On PC1, open the DebugApp demo. 4. Select the port that is connected to PC2 and press the Connect Button.
Appendix A
Application Demonstrations
A-15
When the Connect button is pressed the message Type text below using computer keyboard is sent to the console on PC2. The MIDlet waits for an input stream.
5. On PC2, type the character A into the Input field and press the Send button.
A-16
6. On PC1 check the emulator to see the incoming message from the console.
A.8
Demo3D
This application contains three MIDlets that show off the emulators support of JSR 184, the Mobile 3D Graphics API.
A.8.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 four neighbors die of loneliness, while cells with more than five neighbors die of overcrowding. An empty cell with exactly four neighbors becomes a new live cell. The view of the playing board rotates slowly so you can view the board from all angles.
Appendix A
Application Demonstrations
A-17
FIGURE A-13
The keypad buttons in TABLE A-2 provide control over the game.
TABLE A-2 Button
Description
0 1 2 3 4 5 *
Pause the animation. Resume the animation at its default speed. Speed up the animation. Slow down the animation. Choose the previous preset configuration from an arbitrary list. The name of the configuration is shown at the top of the screen. Choose the next preset configuration from the list. Generate a random configuration and animate until it stabilizes or dies. If it dies, generate a new random configuration.
The source code for this example is particularly well documented. Take a look at toolkit\apps\Demo3D\src\com\superscape\m3g\wtksamples\life3d\ Life3D.java.
A.8.2
PogoRoo
PogoRoo shows a kangaroo bouncing up and down on a pogo stick. To steer the kangaroo, use 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 key to see an effect.
A-18
FIGURE A-14
Bouncing Kangaroo
A.8.3
retainedmode
The retainedmode MIDlet plays a scene file that shows a tireless skateboarder in an endless loop.
Appendix A
Application Demonstrations
A-19
FIGURE A-15
Tireless Skateboarder
A.9
Demos
This demo contains several MIDlets that highlight different MIDP features.
A.9.1
Colors
This application displays a large horizontal rectangle that runs the width of the screen. Below, ten small vertical rectangles span the screen. Finally, three horizontal color bars indicate values for blue, green, and red (RGB). Values are expressed as decimal (0-255) or hexadecimal (00-ff) based on the first menu selection.
To select a vertical bar to change, use the up navigation arrow to move to the color bars. Use the right navigation arrow to highlight a color bar. The large rectangle becomes the color of the selected bar. Use the up or down selection arrows to choose the value to change (red, green, or blue). Use the left or right arrow keys to increase or decrease the selected value. The second menu item allows you to jump in increments of 4 (Fine) or 32 (coarse). You can change the color on any o93r all of the vertical bars.
A.9.2
Properties
This MIDlet displays property values. For example, see FIGURE A-16:
A-20
FIGURE A-16
System Properties
A.9.3
Http
This test application uses an HTTP connection to request a web page. The request is issued with HTTP protocol GET or POST methods. If the HEAD method is used, the head properties are read from the request. Preparing to Run the Demo Before beginning, examine your settings as follows.
Go to Preferences > Security. Set the policy to JTWI and the domain to maximum. In Preferences > Network Configuration, the HTTP version must be 1.1. If you are behind a firewall, go to Preferences > Network Configuration and specify your proxy server information. If you are running antivirus software, you might need to create a rule that allows this MIDlet to allow connections to and from a specific web site.
Running the Demo Launch the Http MIDlet. By default the MIDlet attempts to contact http://www.yahoo.com. To test, choose the Menu soft key and choose 1, 2, or 3 to test the selected URL. Http Test returns the information it is able to obtain. If the information fills the screen use the down arrow to scroll to the end. The amount of information depends on the type of request and on the amount of META information the page provides. To provide body information or content, the page must declare CONTENT-LENGTH as described in RFC 2616.
Appendix A
Application Demonstrations
A-21
Using Menu Options Use the Menu soft key for the following actions.
Choose 1 to GET information from the selected page. Choose 2 to obtain the POST information from the selected page. Choose 3 to display the HEAD attributes for the page. Choose 4 to bring up the current list of web pages. You can chose a new page or add your own page to the list. To specify a new URL, choose the Menu soft key and choose 4. The screen displays http://. Type in the rest of the URL, making sure to end with a slash (/). For example http://www.internetnews.com/. Press the OK soft button. The Http Test screen shows your new URL and prompts for an action.
A.9.4
FontTestlet
This MIDlet shows the various fonts available: Proportional, Regular, Regular Italic, Bold Plain, and Bold Italic. Choose 1 or 2 from the menu to toggle between the system font (sans serif) and the monospace font.
A.9.5
Stock
Like the Http demonstration, This sample uses an HTTP connection to obtain information. Use the same preparation steps as Section A.9.3, Http on page A-21. Run the Demos project and launch the Stock MIDlet. By default, the screen displays an empty ticker bar at the top. Below the ticker, the menu list shows four applications: Stock Tracker, What If? Alerts, and Settings. You must add stock symbols before you can use the first three applications.
A.9.5.1
A-22
The display prompts you to enter a stock symbol. Type SUNW and select the Done soft key. The stock you added and its current value is now displayed in the ticker. Add a few more stock symbols, such as IBM and HPQ.
Remove a Stock
Select Remove a Stock. You see a list of the stocks you have added. Use the navigation keys to select one or more stocks to remove. Choose the Done soft key.
A.9.5.2
Stock Tracker
Stock Tracker displays a list of the stocks you added and their current values. Stock tracker display additional information about the selected stock, for example, the last trade and the high and low values. Choose a stock and press SELECT.
A.9.5.3
What If?
What If? is an application that asks for the original purchase price and the number of shares you own. It calculates your profit or loss based on the current price. Select a stock symbol. Enter the purchase price and the number of shares, then press Calc.
A.9.5.4
Alerts
This application sends you a notification when the price changes to a value you specify. From the main menu, select Alerts. Select Add. Choose a Stock. The screen prompts, Alert me when a stock reaches. Enter an integer.
Appendix A Application Demonstrations A-23
The alert is placed on the Current Alerts list. To remove an alert, press Remove and select the alert. Choose the Done soft key. When the value is reached you hear a ring and receive a message. For example, Symbol has reached your price point of $value and is currently trading at $current_value. Once the alert is triggered it disappears from the Current Alerts list.
A.9.6
Tickets
This demonstrates how an online ticket auction application might behave. The home screen displays a ticket ticker across the top. The Choose a Band field displays Alanis Morrisette by default. To select a band, highlight the band name and press SELECT. Use the down arrow to highlight a different band, moby, for example, then press SELECT. The available auction appears. To make a bid, select the Menu soft key and choose 2. Use the arrow keys to move from field to field. Fill out each field. Select the Next soft key. The application asks you to confirm your bid. Use the arrow keys to highlight Submit then press SELECT. You receive a Confirmation number. Click Bands to return to the welcome page. To set an alert, select the Menu soft key and choose 3. Use the navigation arrows to move to the field and type in a value higher than the current bid. Select the Save soft key. You are returned to the welcome page. You can trigger the alert by making a bid that exceeds your alert value. Your settings determine how often the application checks for changes, so the alert may not sound for a few minutes. To add a band, select the Menu soft key and choose 4. Type in a band name or a comma-separated list of names. Choose the Save soft key. After confirmation you are returned to the welcome page. The added band(s) are displayed in the Choose a Band drop down. This is only a demonstration. To fully describe the band you must edit the file:
toolkit\apps\Demos\src\example\auction\NewTicketAuction.java
To remove a band, select the Menu soft key and choose 5. Navigate to a band then choose SELECT to mark the check box. You can select multiple bands. Choose the Save soft key. To display the current settings for ticker display, updates, alert volume, and date, select the Menu soft key and choose 6. If desired, use the arrow keys and the select key to change these values. Choose the Save soft key.
A-24
A.9.7
ManyBalls
This MIDlet starts with one ball traveling the screen. Use the up and down arrows to accelerate or decelerate the ball speed (fps). Use the right or left arrows to increase or decrease the number of balls.
A.10
GoSIP
GoSIP is a chat application that uses SIP to set up communications using a SIP proxy server and registrar. Begin by running the SIP server. Choose File > Utilities from the KToolbar menu. Select Start SIP Server and press Launch. The SIP proxy server window appears. Click Start to run the server. With the server you can confirm a successful registration attempt.
Appendix A
Application Demonstrations
A-25
FIGURE A-17
Next, run two instances of the emulator with the GoSIP application. In the first emulator, launch Sippy A. You are prompted for the proxy host. Enter your local machine name or IP address and choose Next, then Register. In the SIP server window, SIP messages from the emulator appear. Sippy A appears in the list of registered users. The emulator suggests you invite your friend Sippy B to talk. Dont do it yet.
A-26
In the second emulator, launch Sippy B. Just as before, enter the address of the SIP proxy, choose Next, then Register. The Sippy B user appears in the SIP server window. In the first emulator (Sippy A), choose Invite. The second emulator (Sippy B) indicates that its ringing and displays an IP address. Choose Answer to start the chat. Both emulators now show a Talking screen. You can send messages back and forth using the Send command. When you are finished, choose Bye to end the chat.
A.11
i18nDemo
This MIDlet suite shows off the JSR 238 Mobile Internationalization API. The MIDlets String Comparator and Formatter show how to sort strings and display numbers appropriately for different locales. The third MIDlet, MicroLexicon, is a small phrase translator that comes in handy if you need to ask for a beer in Prague, Herzliya, Beijing, Milan, or several other locations.
Note The default fonts for the Sprint Wireless Toolkit do not support Chinese and Japanese. To use these languages, follow these steps before running this demo:
1. Install a True Type font that supports Chinese or Japanese. 2. Modify toolkit\devices\skin-directory\skin.properties to specify that font. To run a MIDlet, use SELECT to highlight the MIDlet, then use the lower right button to Launch the MIDLet. The String Comparator MIDlet demonstrates how strings (city names) are sorted differently depending on locale. Launch the MIDlet. Use the lower right button to view the menu. Click or Type 2 to select Sort - default, and the list is sorted alphabetically. Click or Type 3 to select Sort - slovak. Its easy to see the difference in the cities that begin with the letter Z, with and without the mark on top. Click Exit to return to the list of MIDlets. The second MIDlet, Formatter, simply displays times and numbers formatted for different locales. Click next to view all four screens. Click Exit to return to the list of MIDlets. The final MIDlet, MicroLexicon, translates phrases from one language to another language. To select the target language from the list, use the navigation arrows to highlight Choose Language. Click SELECT to view the language drop down. Use the navigation arrows to choose a language (see FIGURE A-15) and then click SELECT.
Appendix A Application Demonstrations A-27
FIGURE A-18
MicroLexicon displays a list of phrases. Highlight one and press the SELECT button on the emulator. You see the flag of the target language and the translated phrase. To change the source language, choose Edit > Preferences from the KToolbar menu. Click the i18n tab and enter a valid locale string. The next time you run the emulator and MicroLexicon, the instruction text appears in the given locale, if it is supported. One example that works is cs-CZ. MicroLexicon is powered by MIDlet resources. To understand how you can use the toolkit to localize an application, choose Project > i18n Resources Manager from the KToolbar menu. All the resources, both text and images, used by MicroLexicon, appear. You can edit the resources and run MicroLexicon again to see what happens. You dont need to build the application again because the resources are loaded at runtime.
A-28
FIGURE A-19
A.12
JBricks
JBricks is a game that demonstrates the use of the JSR 229 Payment API. The game itself resembles Breakout or Arkanoid. In JBricks, you can buy another life or a new game level. Behind the scenes, the Payment API handles the details.
Appendix A
Application Demonstrations
A-29
To use the payment features of JBricks, use Project > Run via OTA to install JBricks into the emulator. If you dont know how to do this, read about it in Section 2.3.2, Install on page 2-10. To see how JBricks uses the Payment API, choose either Buy Life or Buy Level from the games main menu. Next, choose whether you want to buy a single life or three lives for a reduced price. The next screen gives you a choice of payment types.
FIGURE A-20
Use the navigation arrows to select the line starting with Pay by. Click the SELECT button to see the possible credit card adaptors in a drop down menu. Use the navigation arrows to select the VISA adaptor, then click SELECT. Click Yes on the lower right to proceed. Next, you are able to enter credit card information. Use any valid VISA number (for example, 4111411141114111) and a valid expiration date.
A-30
FIGURE A-21
To view the transactions for the current instance of the emulator, choose MIDlet > External Events and click the Payment Transactions tab. Transactions for this specific instance of the emulator appear.
Appendix A
Application Demonstrations
A-31
FIGURE A-22
Viewing Transactions
In addition, you can view all transactions passing through the toolkits payment system. Choose File > Utilities, then select Payment Console. A transaction in the console looks something like the following:
A-32
PSP Console running, using phone number +5555555555. PSP Server running at https://localhost:-1 Received Payment Request from 127.0.0.1 Credit card issued by: VISA Credit Card type: 0 Credit Card Number: 4111111111111111 Credit Card Holder: Jonathan Knudsen Feature ID: 3_lives Credit Card Verification Number (CCV): 123 Payload: null Response to 127.0.0.1 HTTP/1.1 200 OK Content-Length: 0 Pay-Response: SUCCESSFUL Pay-Timestamp: 1156282954734
A.13
JSR172Demo
JSR172Demo shows how to access a web service from a MIDlet. The web service is already running on an Internet server. If you are behind a firewall, you must configure the emulators proxy server settings. Choose Edit > Preferences from the KToolbar menu, then select Network Configuration. Fill in the proxy server address file and the port number. Build and run the example. JSR172Demo contains a single MIDlet named Server Script. Launch it and follow the prompts. You can browse through simulated news headlines, all of which are retrieved from the web service.
A.14
KeyEventDemo
This application contains a MIDlet that describes key events. The recognized events are Pressed, Repeated, and Released. For every action performed on a key, the screen displays the corresponding event. For example, when you press the 1 key, the screen displays 1 pressed.
Appendix A
Application Demonstrations
A-33
A.15
LX260-Test-S05
This LX260 device has a full QWERTY keyboard that slides out from the side. The display must switch from portrait mode to landscape mode and back when the device is rotated. The rotation affects forms, lists, scrolling, and word-wrap. This demonstration shows two features:
Ability to switch between full screen and regular screen on the canvas. The regular screen shows a title bar at the top and a soft key bar at the bottom. In full screen mode the title bar is gone and items on the soft key bar occupy the minimum space. Ability to switch the display from canvas to a form.
1. Open the LX260-Test-S05 project. 2. Select the MIDP 2.0 Power Vision platform. On the Devices tab, select the LX260. 3. Click Run. The demo launches in the portrait view. The screen text indicates the form factor value is Open and the usable portion of the screen is 176x180.
From the menu select 1 ToggleFullScrn. Note the screen height has changed from 180 to 220 and observe the appearance of the soft keys.
Select Frm/Cnvs. You see the form and a text string that wraps in the portrait view.
A-34
FIGURE A-23
4. In the emulator select MIDlet > External events. On the Non-Protected Properties tab, locate Form Factor and click the Closed radio button. The display switches to the landscape view. FIGURE A-24 shows the demo screens as they appear in landscape view. Note the changed screen dimensions and line endings.
FIGURE A-24
Appendix A
Application Demonstrations
A-35
A.16
MobileMediaAPI
The MobileMediaAPI application contains four MIDlets that showcase the toolkits multimedia capabilities. This section describes the MIDlets and includes additional information about using multimedia from your applications.
A.16.1
Simple Tones
The Simple Tones example demonstrates how to use interactive synthetic tones. Select an example, then click Play on the lower right.
Short Single Tone and Long Single Tone use Manager.playTone() to play tones with different pitch. Short MIDI event plays a chord on the interactive MIDI device (locator "device://midi"). The shortMidiEvent() method of MIDIControl is used to trigger the notes of the chord. To run the MMAPI Drummer demo, click or type number keys (0-9). Each number plays a different sound.
A.16.2
Simple Player
The Simple Player application demonstrates the range of audio and video capabilities of the emulator. It includes sample files in a variety of formats and can play files from the emulator's persistent storage or from HTTP URLs. The player portion uses a generic javax.microedition.media.Player interface. The player displays duration, media time, and controls for running the media file. If metadata is available in a file, the player enables you to view the information, such as author and title. In the case of MIDI files, if karaoke text is present in the file, it displays on the screen during play. Graphical user interface controls can be viewed on the display screen if applicable. You can access these controls by selecting one of the media samples in Simple Player, then pressing the Menu button to view and select the desired command. Select Simple Player then click Launch. The demo includes the following media samples:
Bong plays a short WAV file. You can adjust certain playback features, as described later in this document. The display shows the duration of the sound in minutes:seconds:tenths of a second, for example 00:17:5. This audio sample is a resource file in the MIDlet suite JAR file.
A-36
MIDI Scale plays a sample musical scale. The display shows the title of the selected music file, the duration of the song, the elapsed time during playback, and the current tempo in beats per minute (bpm). This MIDI file is stored in the MIDlet suite JAR file. Simple Ring Tone plays a short sequence of Beethoven's Fifth Symphony. The display shows the title of the selected music file, the duration of the song, the elapsed time in seconds and tenths of a second during playback, and the current tempo in beats per minute (bpm). This ringtone file (.jts format) is stored in the MIDlet suite JAR file. WAV Music plays a brief audio file. The display shows the title of the audio file, the duration of the audio the elapsed time during playback, and the playback rate in percent. This WAV file is retrieved from an HTTP server. MIDI Scale plays a MIDI file that is retrieved from an HTTP server. The Animated GIF example shows an animated GIF that counts from 1 to 5. The file is stored in the MIDlet suite JAR file. Audio Capture from a default device lets you capture audio from a microphone or connected device. The sound is captured and played back on the speaker. To avoid feedback, use a headset. Video Capture Simulation simulates viewing input video such as might be possible on a device equipped with a camera. MPEG1 Video [http]. Plays an MPEG video found at http://java.sun.com/products/java-media/mma/media/testmpeg.mpg. [enter URL] allows you to play back media files from arbitrary HTTP servers. Type a valid URL (for example, http://java.sun.com/products/javamedia/mma/media/test-wav.mpg) at the insertion point and click OK to play a file. If you want to open an HTTP directory from which to select media, be sure to add a slash to the end of the URL.
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.
Appendix A
Application Demonstrations
A-37
The Simple Player includes 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.
TABLE A-3 Command
Mute/Unmute Volume META Data Stop in 5 seconds Rate Tempo Pitch Start/Stop Recording
0 * and #
Turns off sound but the file continues to play. This command toggles to Unmute. Increases or decreases loudness. Displays information provided by the media file such as copyright information, title, and track list. Pauses the audio play in five seconds when set during playback.
4 and 6
Alters the rate of speed of playback. Increases or decreases the tempo of the tone sequence or MIDI file.
up and down
Lowers or raises the notes in a MIDI file. Records the audio playback. A file is created containing the 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.
Jumps forward or backward one frame at a time in a video file. Starts or stops the media. 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.
1 and 3
Skips forward or backward five percent of the duration of the media file. The sound track syncs to the video. Returns to the start time of the audio playback.
Stops playback and rewinds to the start time. Displays a list of commands and keypad buttons.
A-38
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.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. Animated GIFs and video capture can be implemented using either a Form Item or a Canvas. The Video demonstration includes all the possibilities. Animated GIF Form [jar] shows an animated GIF as a Form Item. The form also includes some information about the playback, including the current time. Choose the Snapshot command to take a snapshot of the running animation. The snapshot is placed in the form following the animated GIF.
Animated GIF - Canvas [jar] shows an animated GIF in a Canvas. A simple indicator shows the progress through the animation. Choose Snapshot to get a still image of the current appearance. The snapshot is shown briefly, then the display goes back to the animation. Video Capture - Form simulates capturing video from a camera or other source and showing it as an Item in a Form. Choose the Snapshot command to take a snapshot of the captured video. The snapshot is placed in the form following the video capture. Video Capture - Canvas simulates capturing video from a camera or other source and showing it in a Canvas. Choose Snapshot to get a still image of the current appearance. The snapshot is shown briefly, then the display goes back to the video capture. MPEG1 Video - Form, MPEG1 Video - Canvas The MPEG1 applications obtain MPEGs from the web, so if you are behind a firewall, you must configure the emulators proxy server settings. Choose Edit > Preferences from the KToolbar menu, then select Network Configuration. Check Use proxy server. Fill in the proxy server address field and the port number. For this demo, select HTTP/1.0. When you play the demo, expect to wait a few seconds while the toolkit obtains the data. The MPEG1 demos have the same behavior as Video Capture - Form and Video Capture - Canvas, respectively.
Appendix A
Application Demonstrations
A-39
A.16.3
A.16.4
Name of the nth media title to be played back by the Simple Player MIDlet. Location of the nth media title, PlayerTitle-n, to be played back by the Simple Player MIDlet. The name of the nth media title to be played back by the Video application. Location of the nth media title, VideoTest-n, to be played back by the Video application.
A.17
MP4Player Demo
This section demonstrates the ability to play MP4 files on the external screen. 1. On the main MIDlet (the open phone) screen, press the soft key below Launch. Wait a few seconds while the player initializes. 2. The midlet displays instructions on how to play and pause the MP4 file. 3. Click the Invoke soft key to start playing the movie. You can Pause (2), Forward (3), or Rewind (1) the movie according to the instructions. See FIGURE A-25.
A-40
FIGURE A-25
While the demo is running you can play the movie on the External Canvas. Follow these steps: 1. Select MIDlet > External Events. In the External Event Generator, select the Sprint System States tab. 2. Change the Form Factor property from Open to Closed. The display is transferred to the External Canvas as shown in FIGURE A-26. To play, pause, play, forward or rewind the movie, use the external buttons on the device.
Appendix A
Application Demonstrations
A-41
FIGURE A-26
A-42
A.18
Muglet Demo
This section demonstrates the Muglet capabilities defined in the Sprint API.
MugletDemo: the manager MIDlet. AudioMIDlet: knows how to play an audio file (uses Sprint media API). ViewerMIDlet: knows how to display images.
1. In the tool bar, click Open Project. 2. Choose MugletDemo from the project list and click the Open Project button. 3. Click the Run via OTA button. 4. On the main MIDlet (the open phone) screen, press the soft key corresponding to Apps. You see the Applications screen. 5. Click the soft key beneath Launch. You see Install Application on the screen. a. Click the soft key beneath Menu. Press 2 to launch the installation. b. The application suggests a local website. Click the Menu soft key. Press 1 to accept the site. c. The application displays a JAD file. Click the Install soft key. The JAD file downloads, then it is verified. The application asks you to confirm the installation. click the Install soft key. Continue through any warnings. 6. The application asks if you want to launch the MugletDemo.jad. Click the OK soft key. The three midlets are displayed on the screen (FIGURE A-27).
Appendix A
Application Demonstrations
A-43
FIGURE A-27
7. Click the Launch soft key to run the selected JAD. Click the Launch soft key to launch the selected MugletDemo. Muglet options are displayed (FIGURE A-28).
FIGURE A-28
MugletDemo Options
8. Click the Launch soft key to play the selected item (bubbles.mp3). 9. To play a different selection, click Back to return to the Options screen. Use arrow keys or the phones navigation key to move up and down the list. Click the Launch soft key to play the selection.
A-44
A.19
Multitasking VM Demo
This procedure uses demo projects to highlight Multitasking VM (MVM) features. Before beginning, add some MP3 or MP4 files to the database for the Multitasking VM device you are using. For example: install-dir\appdb\DeviceName\filesystem\memorycard. The Multitasking VM demos have settings that determine how they will interact with other Multitasking VM applications, as summarized in TABLE A-5.
TABLE A-5 Demo
MP4Player
MIDlet-Heap-Size
555555
1. Open the MVMDemoBackgroundNoPause project and click Run via OTA. 2. Choose Install Application and upload the demo. Follow the prompts until the installation is complete. 3. Choose the Exit soft key or click the X in the window border to close the emulator window. 4. Repeat steps 1 through 3 for MVMDemoLaunchBackground, and MVMDemoPowerOn. Three MVM demos are now loaded in the emulator. 5. Open the MP4Player project. a. Click the Settings button. b. Select the User Defined icon and change the MIDlet-Heap-Size to 111111. c. Click the Package button. d. Click Sign to sign the MIDlet. e. Click Run via OTA. MVMDemoPowerOn launches immediately. This happens because MIDlet-Launch-Power-On is set to yes.
Appendix A
Application Demonstrations
A-45
6. Press the End key, and choose Send to Background. As shown in FIGURE A-29, MVMDemoPowerOn has a green check showing it is running in the background.
FIGURE A-29
Application Manager
7. Select MVMDemoPowerOn. Go to the soft menu and remove this application. 8. Select Install Application to install the player. When you invoke the player you see this message: The application has unexpectedly quite because it ran out of memory. Click Done. 9. In the AMS, select the MP4Player and Remove it. Close the emulator. 10. In KToolbar, reset the MIDlet-Heap-Size to 555555, package and sign the application, and Run via OTA. a. Install the MP4Player application. b. Select MP4Player and launch the application. Select Invoke to play. The MP4 player runs. c. Click End. Select Exit Application. You are returned to the AMS. Note, theres no green check because you exited rather than sending the player to the background. 11. Launch MVMDemoLaunchBackground. A green check signifies the application is running. You dont see anything else because MIDlet-Launch-Background is set to yes. This attribute is typically used for service MIDlets. 12. Launch MVMDemoBackgroundNoPause. Wait for the /memorycard folder to appear. Select the folder. 13. Browse to the Music folder and select an MP3 file.
A-46 Sprint Wireless Toolkit 3.2 Users Guide December 2007
14. Press the End key and choose Go to the Application Manager. You return to the application manager while the file you launched in Step 13 continues to play in the background. A green check appears by the application. 15. In the Application Manager, launch the MP4Player demo. Press the Invoke key. The MP4Player plays in the foreground, replacing the MP3 file. 16. Close the emulator to end this demo.
A.20
Network Demo
This demo has two MIDlets: Socket Demo and Datagram Demo. Each demo requires you to run two emulator instances so that you can emulate the server and client relationship.
A.20.1
Socket Demo
Run two instances of the emulator. One acts as the socket server, and the other as the socket client. In the first emulator, launch the application, then select the Server peer. Choose Start. The emulator explains that the demo wants to send and receive data over the network and asks, Is it OK to use network? Choose Yes. The Socket Server displays a screen that indicates it is waiting for a connection. In the second emulator, launch the application, select the Client peer, then choose Start. The emulator explains that the demo wants to send and receive data over the network and asks, Is it OK to use network? Choose Yes. The Socket Client displays a screen that indicates it is connected to the server. Use the down navigation arrow to highlight the Send box. Type a message in the Send box, then choose the Send soft key. For example, in the client, type Hello Server In the Send box (see FIGURE A-30). Choose the Send soft key. The emulator activates a blue light during the transmission.
Appendix A
Application Demonstrations
A-47
FIGURE A-30
On the emulator running the Socket Server, the Status reads: Message received Hello Server. You can use the down arrow to move to the Send box and type a reply. For example, Hello Client, I heard you. Select Send. See FIGURE A-31.
FIGURE A-31
Back in the Socket Client, the status shows the message received from the server. The Send box contains the previous message you sent.
A.20.2
Datagram Demo
This demo is similar to Socket Demo.
A-48
Run two instances of the emulator. One acts as the datagram server, and the other as the datagram client. In the first emulator, launch Datagram Demo, then select the Server peer. Choose Start. The emulator explains that the demo wants to send and receive data over the network and asks, Is it OK to use network? Choose Yes. Initially, the Datagram Server status is Waiting for connection, and the Send box is empty. In the second emulator, launch Datagram Demo, select the Client peer, then choose Start. The emulator explains that the demo wants to send and receive data over the network and asks, Is it OK to use network? Choose Yes. The Datagram Client status is: Connected to server. Use the down navigation arrow to highlight the Send box. Type a message in the Send box, then choose the Send soft key. For example, type Hello datagram server. On the emulator running the Datagram Server, the Status displays: Message received - Hello datagram server. You can use the down arrow to move to the Send box and type a reply to the client. In the Datagram Client, the status field displays the message received from the server. The Send box contains the last message you sent.
A.21
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. Run two instances of the emulator. One listens for incoming connections, while the other attempts to send an image. In the first emulator, launch the application then choose Obex Demo, then Receive Image. The emulator explains that an OBEX connection allows other devices to talk to yours and asks, Is it OK to make the connection? Choose Yes. The listener emulator displays a screen that indicates it is waiting for incoming connections. In the second emulator (the sender), launch Obex Demo, then choose Send Image. You see a list of images. Select one and choose Send. The emulator explains the demo wants to make an outgoing client connection, and asks if it is OK. Choose Yes. The Send Image utility uploads the image. In the listening emulator, the utility displays information about the incoming image and asks Would you like to receive it? See FIGURE A-32.
Appendix A
Application Demonstrations
A-49
FIGURE A-32
Choose Yes. The image you selected is transferred over the simulated infrared link and displayed on the first emulator. See FIGURE A-33.
FIGURE A-33
A.22
PDAPDemo
PDAPDemo shows how to use the PIM and FileConnection APIs that are part of the JSR 75 specification.
A-50
A.22.1
Browsing Files
PDAPDemo shows how to use the PIM and FileConnection APIs that are part of the JSR 75 specification.
A.22.2
Browsing Files
To run the file browser, you must give the MIDlet appropriate security authorization. The easiest way to do this is to choose Edit > Preferences... from the KToolbar menu. Click the Security tab. Change the Security domain to maximum and press OK. Now open and run the PDAPDemo project. Launch the FileBrowser MIDlet. You see a directory listing. You can browse through the available directories and files. By default there is one directory, memorycard.
FIGURE A-34
Browsing Files
Select a directory and press the select button to enter it. The memorycard directory contains a single file, file.txt, and an empty directory, photos.
Appendix A
Application Demonstrations
A-51
FIGURE A-35
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.
FIGURE A-36
The actual files are located in toolkit\appdb\skin\filesystem, where skin is the emulator skin you are using. You can add files and root directories as you wish and they are visible to the JSR 75 File API. See Chapter 11 for more information.
A-52
A.22.3
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.
Appendix A
Application Demonstrations
A-53
FIGURE A-38
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.
FIGURE A-39
A-54
FIGURE A-40
Saving an Item
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 11 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.23
Razr2Demo
1. Open the RAZR2 Project. 2. Select the MIDP 2.0 Power Vision platform. On the Devices tab, select the MotorolaRAZR2 device. 3. Click Run via OTA. 4. Install and launch the demo. In the emulator, the demo instructs you to close the form factor.
Appendix A
Application Demonstrations
A-55
5. Select MIDlet > External events. On the Non-Protected Properties tab, find Form Factor and select the Close radio button. A player launches on the external screen as shown in FIGURE A-41.
FIGURE A-41
Click > to play a clip. As you click buttons, the action is displayed in the title area.
A.24
RecordStoreDemo
This application contains a MIDlet that demonstrates the use of RecordStore, as defined in the MIDP 1.0 and MIDP 2.0 APIs. The demo enables you to create new RecordStore objects. A RecordStore object can contain records. Open the Record Store project and launch the application. The Record Stores screen shows a list of Record Stores. Initially the screen is empty. To add a Record Store, click Add new on the lower left. All you need to do is specify a record name.
A-56
FIGURE A-42
Initial Screen
As shown in FIGURE A-43, you are prompted to enter the name of the new record store. After entering the name, click the Done soft button. You can enter multiple Record Store names.
FIGURE A-43
The Record Stores listing now shows the name of the record store you created (in this case User1). To view its properties, select the record store name, open the Menu, and select 2, Properties. As shown in FIGURE A-44, the Properties screen shows the Record store properties.
Appendix A
Application Demonstrations
A-57
FIGURE A-44
Note that the store has zero records. Press the Back soft key to return to the list of Records. You can also change a records access modes. There are two modes, access permission, and write permission. By default any MIDlet has both entry access and write permission. You can limit the access so that only the creator MIDlets have access, as shown in FIGURE A-45.
FIGURE A-45
MIDlet Access
Once you have created a record store you can add records to it. Select the record store, open the menu, and select 1, Open. FIGURE A-46 shows the open record store User1. Click the Add record soft key.
A-58
FIGURE A-46
You are prompted to add a record. You can add multiple records to the store. For example, in FIGURE A-47 we added the users service start date, and service level agreement (SLA), and the host server.
Appendix A
Application Demonstrations
A-59
FIGURE A-47
The Record screen menu enables you to edit or delete an existing record, or view its properties. Option 4, Back returns you to the Record Store listing.
FIGURE A-48
Note that records you enter are displayed in reverse order. You can display the properties for a record. In this example we select Server22, the last entry. To view its
A-60
properties, select Menu, and choose 3, Properties. The properties are as shown in FIGURE A-49. Click Cancel to return to the add Record screen.
FIGURE A-49
In the Record screen, select User1, and select Option 2, Properties. Figure shows the Record properties. Note that there are now three records, as compared to FIGURE A-44.
Appendix A
Application Demonstrations
A-61
FIGURE A-50
A.25
SATSADemos
SATSADemos includes demonstrations of SATSA, the Security and Trust Services APIs. Most of the demonstrations show how to communicate with a smart card. The emulator can communicate with a simulated smart card using a socket protocol. The smart card simulator, cref, is included with the toolkit. See Chapter 15 for details. The following sections contain instructions for each menu choice for this demo. For each demo, be sure to do the following before launching the emulator:
Run the instance(s) of cref from the command line. Be sure to set the set the security domain to maximum.
A.25.1
APDUMIDlet
This MIDlet demonstrates communication with a smart card using Application Protocol Data Units (APDUs), small packets of data. APDUMIDlet expects to find two simulated smart cards. You can run the smart card simulator using cref, which is part of the Java Card Development Kit. The Mohair application includes pre-built memory images that you can use with cref. The memory images contain Java Card applications with which Mohair interacts. The memory images are in the root directory of the Mohair project.
A-62
Start up two instances of cref like this, one for each simulated card slot (assuming the current directory is the toolkit root directory):
start bin\cref -p 9025 -i apps\SATSADemos\demo2.eeprom start bin\cref -p 9026 -i apps\SATSADemos\demo2.eeprom
Note that the port numbers (9025 and 9026 in this example) must match the port numbers you specified in the SATSA preferences, described in Chapter 15. Also, make sure you use the correct path to demo2.eeprom. Once you have the two smart card simulators running, you can run APDUMIDlet.
A.25.2
SATMIDlet
SATMIDlet demonstrates smart card communication with a slight variation on APDU communication. To set up the simulated smart card, use cref, very much like you did for APDUMIDlet. This time you dont have to specify a port number, and the memory image is different:
start bin\cref -i apps\SATSADemos\sat.eeprom
When the smart card simulator is running, you can run SATMIDlet to communicate with card applications.
A.25.3
CryptoMIDlet
CryptoMIDlet demonstrates the general cryptographic features of SATSA. It does not interact with a smart card in any way.
A.25.4
MohairMIDlet
MohairMIDlet has two functions. The first, Find slots, displays all the available card slots. Each slot has a number followed by C or H indicating whether the slot is cold-swappable or hot-swappable. After viewing the slots select Back to return to the first screen. The second part of MohairMIDlet, SATSA-PKI Sign test, uses a smart card to generate a digital signature. As with the earlier demonstrations, you need to run cref with the right memory image to prepare for the connection from MohairMIDlet. Type the following in the installation directory:
Appendix A
Application Demonstrations
A-63
In the emulator, highlight SATSA-PKI Sign test and choose SELECT. The following confirmation message appears: This certificate will be used: MohairAuth Select the OK soft key. For PIN 1, type: 1234 Select the OK soft key. The following confirmation message appears: This string will be signed: JSR 177 Approved Select the OK soft key. The following confirmation message appears: This certificate will be used: MohairAuth Select the OK soft key. For non repudiation key 1 PIN, type: 2345
A.26
SATSAJCRMIDemo
This application contains a single MIDlet, JCRMIMIDlet, which shows how to communicate with a card application using Java Card RMI, a card-friendly remote object protocol. As with some of the MIDlets in SATSADemos, you need to start up cref with an appropriate memory image:
start bin\cref -p 9025 -i apps\SATSADemos\demo2.eeprom
Now run JCRMIMIDlet to see how your application can communicate with a distributed object on the card.
A.27
SIPDemo
This application is a very simple example of using SIP to communicate directly between two devices. Usually devices use SIP with a proxy server to set up direct communications of some kind. For a more complete example involving a proxy, take a look at GoSip.
A-64
To see how SIPDemo works, run two instances of the emulator. In the first, choose Receive message. You can use the default port, 5070, and choose Receive. The first emulator is now listening for incoming messages. In the second emulator, choose Send message. Fill in values for the recipient, port number, subject, and message, or accept the defaults, and choose Send. Your message is displayed in the first emulator. The first emulators response is displayed in the second emulator.
A.28
SprintDemo
The Sprint demo demonstrates several Sprint API capabilities.
A.28.1
Appendix A
Application Demonstrations
A-65
FIGURE A-51
A.28.2
SystemStates Demo
This demo demonstrates the Sprint System API options. 1. Open and run the SprintDemo. 2. Select the SystemStates demo. 3. Click the Launch soft key. The application displays three options, each of them demonstrating a different aspect of the System API. 4. Use the Launch soft key to select an option. 5. Select a property and use the Launch soft key to display it.
A-66
System Events option: Presents the values the MIDlet retrieves by calling the getSystemState method.
System Events Options
FIGURE A-52
System Properties option: Presents a list of properties. When you choose one of the properties on the list, the getSystemState method is called to show the property's value on the screen.
System Properties
FIGURE A-53
Appendix A
Application Demonstrations
A-67
System Protected Properties option: Presents a list of protected properties. When you choose one of the properties on the list, the getProtectedProperty method is called to show the property's value on screen.
System Protected Properties
FIGURE A-54
A.28.3
Media Demo
The media demo demonstrates the Sprint media API. 1. Open and run the SprintDemo project. 2. Use the phones navigation keys or your keyboard arrow keys to select the Media option. Click the Launch soft key. 3. Choose the Media option. The application displays two options. Use the Launch soft key run the demo:
Player option Demonstrates the options to Play, Stop, Pause, and Resume a media file. Use Play to start the clip. If you select stop, select play to start from the beginning. If you select pause, select resume to start from the point you pressed pause. Vibrate option Simulates handset vibration.
A-68
A.29
SVGContactList
This application uses different skins to display the same contact list information and a news banner. The skins have different colors and fonts. Select SVGContactlist(skin 1) or SVGContactlist(skin 2), then click Launch. Use the up and down arrows to navigate the list of contacts. The highlighted name is marked with a special character (a > or a dot) and is displayed in a larger font.
FIGURE A-55
Press the select button to see more information for the highlighted name.
Appendix A
Application Demonstrations
A-69
FIGURE A-56
A.30
SVGDemo
This suite contains MIDlets that demonstrate different ways of using the JSR 226 Scalable 2D Vector Graphics API for J2ME. This API provides ways to load manipulate, render, and play SVG content. The Scalable Vector Graphics (SVG) 1.1 specification defines a language for describing two-dimensional graphics in XML. The full specification is available at http://www.w3.org/TR/SVG11/. SVG Tiny (SVGT) is a subset of SVG that is appropriate for small devices like mobile phones. See http://www.w3.org/TR/SVGMobile/. SVG Tiny is a compact yet powerful XML format for describing rich, interactive, and animated 2D content. Graphical elements can be logically grouped and identified by the SVG markup.
A-70
A.30.1
SVG Browser
The SVGBrowser MIDlet displays SVG files residing in the phone file system. Before running this demo, place an SVG file in the directory workdir\appdb\ DefaultColorPhone\filesystem\root1. Launch the demo. The application displays the contents of root1. Select your SVG file and choose the Open soft key.
A.30.2
A.30.3
import javax.microedition.m2g.ScalableGraphics; import javax.microedition.m2g.SVGImage; ... String svgURI = ...; SVGImage svgImage = (SVGImage) SVGImage.createImage(svgURI, null); SVGAnimator svgAnimator = SVGAnimator.createAnimator(svgImage); // If running a JSE applet, the target component is a JComponent. JComponent svgAnimationComponent = (JComponent) svgAnimator.getTargetComponent(); ...
Appendix A
Application Demonstrations
A-71
svgAnimator.stop();
A.30.4
A.30.5
Bouncing Balls
Bouncing Balls plays an SVG animation. Press 8 to play, 5 to start, and 0 to stop. If you press 8, pressing 5 resumes the animation. If you press 0, pressing 5 starts the animation from the beginning.
A.30.6
Optimized Menu
In this demo, selected icons have a yellow border. As you move to a new icon, it becomes selected and the previous icon flips to the unselected state. If you navigate off the icon grid, selection loops around. That is, if the last icon in a row is selected, moving right selects the first icon in the same row. This demo illustrates the flexibility that combining UI markup and Java offers: a rich set of functionality (graphics, animations, high-end 2D rendering) and flexibility in graphic manipulation, pre-rendering or playing. In this example, a graphic artist delivered an SVG animation defining the transition state for the menu icons, from the unselected state to the selected state. The program renders each icon's animation sequence separately into off-screen buffers (for faster rendering later on), using the JSR 226 API. With buffering, the MIDlet is able to adapt to the device display resolution (because the graphics are defined in SVG format) and still retain the speed of bitmap rendering. In addition, the MIDlet is still leveraging the SVG animation capabilities.
A-72
The task of defining the look of the menu items and their animation effect (the job of the graphic artist and designer) is cleanly separated from the task of displaying the menu and starting actions based on menu selection (the job of the developer). The two can vary independently as long as both the artist and the developer observe the SVG document structure conventions.
A.30.7
Picture Decorator
In this demo you use the phone keys to add decorations to a photograph. The key values are:
1 2 3 4 5 6 7 8 9 # key shrink key next picture key grow key help key horizontal flip ley vertical flip key rotate counter-clockwise key previous picture key rotate clockwise display picker options
This demo provides 16 pictures for you to decorate. Use the 2 and 6 keys to page forward and back through the photos. To decorate, press # to display the picker. Use the arrow keys to highlight a graphic object. The highlighted object is enlarged. Press SELECT to choose the current graphic or press the arrow keys to highlight a different graphic. Press SELECT again to add the graphic to the photo. When the decoration is added you see a red + on the graphic. This means it is selected and can be moved, resized, and manipulated.
Appendix A
Application Demonstrations
A-73
FIGURE A-57
Use the navigation arrows to move the graphic. Use 1 to shrink the graphic, and 3 to enlarge the graphic. Use 5 or 6 to flip, and 7 or 9 to rotate.
When you are satisfied with the position, press SELECT. Note that a green triangle appears. This is a cursor. Use the navigation keys to move the green triangle around the picture. When the cursor is over an object it is highlighted with a red box. Press SELECT. The red + indicates the object is selected.
FIGURE A-58
Highlighted Mustache
To remove a decoration (a property), select an object, then click the Menu soft key. Press 2 to remove a property.
A-74
A.30.8
Location-Based Service
The Itinerary demo uses locations to create an itinerary. Launch the application. A splash screen (also used as the help) appears. Press 4 at any time to retrieve this help screen. The initial map view plots your itinerary (a walk through San Francisco) in red dots. The bay (in blue) is on the right of your screen. Press 1 to start following the itinerary. The application zooms in on your location on the map. Turn-by-turn directions appear in white boxes on the horizontal axis. While the itinerary is running, press 7 to rotate the map counter-clockwise. Note, the map rotates and the text now appears on the vertical axis. Press 7 again to restore the default orientation.
Appendix A
Application Demonstrations
A-75
FIGURE A-59
A.31
UIDemo
This demo provides many examples of UI elements you can use in your applications. The demo names explain their purpose. Most have some interactive capability (navigate and select) and some allow input. Interaction is similar across demos. You can choose items from lists or input data. ChoiceGroup, List: The ChoiceGroup, List, and TextBox demos show the three choice group types: Exclusive (radio buttons), Multiple (check boxes) and Pop-Up (a drop list).
For Exclusive and Multiple, navigate to highlight an object, and use the select capability to pick an option. For pop-ups, highlight the popup and select to open it. Use navigation keys to move up and down the list. Use Select to choose an item. The Alert and DateField demos use pop-ups.
A-76
Input: The CustomItem and TextField, and TextBox demos showcase different input types. Text boxes and fields can be set to accept five types of input (not all elements use all types). These categories act as filters.
Qwerty: Any character on the keyboard. 123: Any numeral ABC: Any letter Predict: Predicts next character based on prior input Symbols. Any symbol
For example, if 123 is assigned to a field and you type abc, nothing will be entered in the field. As shown in FIGURE A-60, Text Fields can display a tip (in this case Qwerty) to prompt the user for acceptable input.
FIGURE A-60
A.32
VirtualKeypadDemo
This demo was created for the Samsung Upstage phone. The virtual keypad allows the user to enter text by choosing characters from a list using the media player interface (instead of flipping the phone over and using the keypad). The virtual keypad uses the same key assignments as the conventional keypad. In KToolbar, open the VirtualKeypadDemo project and choose the MIDP 2.0 MVM platform. Go to the Device tab, and choose the Upstage phone.
Appendix A
Application Demonstrations
A-77
Run the demo. VirtualKeypadDemo lets you enter one string, and VirtualKeypadDeluxe accepts four strings, as shown in FIGURE A-61.
FIGURE A-61
Select a text string and choose Edit from the soft menu. The Enter Text screen displays the selection options. The demo uses the media player controls as described in TABLE A-6.
TABLE A-6 Key
Move up the list Cursor left Select/Tap Cursor right Delete previous character Tap the area below > to move down the list
End
The Menu soft key offers two options: (1) Done and (2) Language. Your language selection determines the characters displayed for each key group. Choose characters using the actions in TABLE A-6 and choose Done from the menu when you are finished.
A-78
FIGURE A-62
A.33
WMADemo
This application shows how to send and receive SMS messages. The Sprint Wireless Toolkit 3.2 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 must 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 dont know how to do this, read about it in Chapter 2. Use the WMA console to send the emulator a message as follows. Choose File > Utilities... and select WMA Console. In the WMA console window, click the Send SMS... button. Choose the number in the SMS message window, then fill in a port number of 50000. Type in a text message and click Send.
Appendix A
Application Demonstrations
A-79
FIGURE A-63
A-80
FIGURE A-64
Choose Yes. The SMSReceive MIDlet is launched and immediately displays the incoming SMS message.
FIGURE A-65
You can also use the WMA console to send and receive MMS messages. See Chapter 8 for more information. If you are attempting to send text messages to WMADemo using the WMA console, make sure to specify the port number as 50000. For MMS messages, use example.mms.MMSDemo as the application ID.
Appendix A
Application Demonstrations
A-81
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 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.
FIGURE A-66
Next, click the Parts tab. The WMA console allow 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.
A-82
FIGURE A-67
Click Send to send the message. The emulator asks if it can launch WMADemo. Click Yes. The image and its information are displayed.
FIGURE A-68
Appendix A
Application Demonstrations
A-83
A-84
APPENDIX
B.1
Prerequisites
Before building and running an application from the command line, verify that you have a version no earlier than 1.5 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.5. 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 toolkit and demo is the name of one of the demo applications.
B.2
B-1
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 toolkit project directory structure. You must use the -bootclasspath option to tell the compiler to use the MIDP APIs, and 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. For more information on javac, consult the J2SE documentation. The next step is to preverify the class files. In the bin directory of the toolkit lives a handy utility called preverify. The syntax for the preverify command is as follows:
preverify options files|directories
Some of the options are as follows: -classpath classpath Specify the directories or JAR files (given as a semicolon-delimited list) from which classes are loaded. -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
B-2
-d classes tmpclasses
As a result of this command, preverified class files are placed in the classes directory. If your application uses WMA, MMAPI, or other versions of CLDC or MIDP, be sure to include the relevant .jar files in the classpath.
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 suites 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 . The arguments are as follows: file: The JAR file to create. manifest: The manifest file for the MIDlets. class_directory: The directory containing the applications classes. resource_directory: The directory containing the applications resources. 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 .
Appendix B
B-3
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. For example, a JAD file might have the following contents:
MIDlet-Name: MyMIDlet MIDlet-Vendor: My Organization MIDlet-Version: 1.0 MIDlet-Jar-URL: MyApp.jar MIDlet-Jar-Size: 24601
B.2.3
Run
You can run the emulator from the command line. The toolkits bin directory contains the command emulator. The syntax for the emulator command is as follows: emulator options The general options are: -help: Display a list of valid options. -version: Display version information about the emulator. -Xquery: Print emulator skin information on the standard output stream and exit immediately. The information includes the skin name, screen size, and other capabilities. Options that pertain to running MIDlet suites are: -Xdevice:skin_name: Run an application on the emulator using the given skin name. For a list of skin names, see Chapter 4, Using the Emulator. -Xdescriptor:jad_file: Run an application locally using the given JAD file. -classpath classpath: Specify the classpath for libraries required to run the application. Use this option when running an application locally. -D runtime_property: Set the HTTP and HTTPS proxy servers. Valid properties include: com.sun.midp.io.http.proxy=proxy host:proxy-port
B-4
-Xjam:command=application: Run an application remotely using the Application Management Software (AMS) to run using OTA provisioning. If no application is specified with the argument, the graphical AMS is run. install=jad_file_url|force|list|storageNames Install the application with the specified JAD file onto a device. run=storage_name| storage_number Run a previously installed application. The application is specified by its valid storage name or storage number. remove=storage_name|storage_number|all Remove a previously installed application. The application is specified by its valid storage name or storage number. Specifying all, all previously installed applications are removed. 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 Display trace output, as specified by a list of comma-separated options: class : trace class loading gc : trace garbage collection all : use all tracing options -Xdebug Enable runtime debugging. The -Xrunjdwp option must also be used. -Xrunjdwp:debug_settings Start a JDWP debug session, as specified by a list of comma-separated debug settings. The -Xdebug option must also be used. Valid debug settings include: 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.
Appendix B Command Line Reference B-5
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).
B.3
Pops up a dialog that allows you to choose the default emulator skin Launches KToolbar Launches the toolkit preferences Launches the toolkit utilities window
B.4
B-6
TABLE B-2
Property Name
http.version
Network Configuration > HTTP Version Value: HTTP/1.1 | HTTP/1.0 Network Configuration > HTTP Address Value: hostname Network Configuration > HTTP Port Value: integer Network Configuration > HTTPS Address Value: hostname Network Configuration > HTTPS Port Value: integer Performance > bits/sec combo box Value: integer Performance>Enablenetworkthroughput emulation Value: true | false Performance > Graphics primitives latency Value: integer Performance > Display refresh (radio button) Value: default | immediate | periodic Performance > Display refresh (slider) Value: integer Performance > Enable VM speed emulation (check box) Value: integer Performance > Enable VM speed emulation (slider) Value: true | false Storage > Storage root directory Value: String (relative path to appdb) Storage > Storage size Value: integer MMedia > Audio Capture Value: true | false
http.proxyHost
http.proxyPort
https.proxyHost
https.proxyPort
netspeed.bitpersecond
netspeed.enableSpeedEmulation
screen.graphicsLatency
screen.refresh.mode
screen.refresh.rate
vmspeed.bytecodespermilli
vmspeed.enableEmulation
storage.root
storage.size
mm.control.capture
Appendix B
B-7
TABLE B-2
Property Name
mm.control.midi
MMedia > MIDI tones Value: true | false MMedia > Audio Mixing Value: true | false MMedia > Audio Record Value: true | false Value: true | false MMedia > MIDI format Value: true | false MMedia > Video format Value: true | false MMedia > WAV Audio format Value: true | false WMA > Phone Number of Next Emulator Value: integer WMA > First Assigned Phone Number Value: integer WMA > % Random Message Fragment Loss Value: integer WMA > Message Fragment Delivery Delay (ms) Value: integer
mm.control.mixing
mm.control.record
mm.control.volume mm.format.midi
mm.format.video
mm.format.wav
wma.client.phoneNumber
wma.server.firstAssignedPhoneNumber
wma.server.percentFragmentLoss
wma.server.deliveryDelayMS
B.5
B-8
B.5.1
B.5.2
-jarfile is the MIDlet-Jar-URL property in the JAD -keystore is %HOMEPATH%\.keystore -certnum is 1-chainnum is 1
B.5.3
Managing Certificates
MEKeyTool manages the public keys of certificate authorities (CAs), making it functionally similar to the keytool utility that comes with the J2SE SDK. The keys can be used to facilitate secure HTTP communication over SSL (HTTPS). 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.5.0/docs/tooldocs/windows/keytool.html for more information. To run MEKeyTool, open a command prompt, change the current directory to toolkit\bin, and enter the following command: mekeytool.exe command The commands are as follows: -help Print the usage instructions for MEKeyTool. -import -alias alias -keystore JCEkeystore -storepass storepass -domain domain_name 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 (-owner owner|-number key_number) Delete a key from the given ME keystore with the given owner. The ME keystore is toolkit\appdb\_main.ks.
Note The toolkit contains an ME keystore called _main.ks, which is located in the
appdb subdirectory. This keystore includes all the certificates that exist in the default J2SE keystore, which comes with the J2SE SDK installation.
B-10
APPENDIX
Localization
This appendix describes setting the language displayed in the Sprint Wireless Toolkit 3.2 and the localization setting of the emulation environment.
C.1
Locale Setting
A locale is a geographic or political region or community that shares the same language, customs, or cultural conventions. In software, a locale is represented by a collection of files, data, and code, which contains the information necessary to adapt software to a specific location. Some software uses a locale to tailor information for users, such as:
By default, all KToolbar strings, that is, the entire User Interface (UI), are displayed in the language of the supported platforms locale. For example, Japanese characters can be displayed in KToolbar running on a Japanese Microsoft Windows machine, provided that the correct localized Sprint Wireless Toolkit 3.2 is downloaded and installed. You can set the wtk.locale property to have the KToolbar displayed in a specified locales 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 Sprint Wireless Toolkit 3.2. 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).
C-1
C.2
Emulated Locale
A devices locale is contained in the system property microedition.locale. You can change the emulators locale by choosing Edit > Preferences from the KToolbar menu, then selecting i18n. Choose a locale from the combo box or type it in directly. For information on microedition.locale, consult the MIDP specification.
C.3
Character Encodings
The CLDC system property, microedition.encoding, defines the default character encoding name of the MIDP environment. In the Sprint Wireless Toolkit 3.2 emulator, this property is set according to the underlying window system you are using. The propertys value is set to the default encoding for the Java SE platform running on the same window system. For example, in an English window system, the encoding setting is as follows:
microedition.encoding=ISO8859_1
You can override the default value by adding the microedition.encoding property to the toolkit\wtklib\platform\ktools.properties file. For example, if you want to use UTF-8 as the default setting on Microsoft Windows, you can set the property in the toolkit\wtklib\Windows\ktools.properties file as follows:
microedition.encoding=UTF-8
Note All the Java SE platform encoders are available in the emulated
environment. See the Sprint Wireless Toolkit 3.2 Basic Customization Guide for information on how to limit the list of available encoders for a specific device. Java Technology Compiler Encoding Setting The javac.encoding property determines the encoding used by the javac compiler to compile your source files. The propertys value is set to the default encoding for the Java SE platform running on the same window system.
C-2
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
C.4
Appendix C
Localization
C-3
C-4
Index
A
access control, 15-3 advanced conguration options, 3-12 application descriptor, 2-9 Application Management Software (AMS), 2-10 applications directory, setting, 3-12 applications, running remotely, 2-20 attributes, 3-3
D
debugging, 2-17 from command line, B-5 with NetBeans IDE, 2-17 debugging options, B-5 demonstrations, A-1 source code, 1-2 deploying on a web server, 2-20 descriptor, 2-9 attributes, 3-3 Developer certicate database, 7-3 development cycle full, 2-8 simple, 2-4
B
BCC, 12-3 Bluetooth preferences, 12-1 Bluetooth simulation, 12-1 building source code, 2-6
C
call graph, 5-4 capture, 9-2 certicate importing, 7-15 certicate management, 7-13 certicate manager utility, B-1 certicates, 7-3 character encodings, C-2 -classpath option, B-2 COMM default connection parameters, 6-10 COMM Terminal, 6-10 command line operations, B-1 command path, B-1
E
emulator, 4-1 card slots, 15-2 default font support, C-3 keyboard shortcuts, 4-3 language support, C-1 locale, 18-1 location, 14-1 performance, 4-8 phone number, 8-1 preferences, 4-6 running solo, 4-12 skins, 4-1 emulator command, B-4 encoding, javac, 3-12 external canvas, 6-1, 19-1
Index-1
F
FileConnection API, 11-1 managing roots, 11-2 font support, C-3
K
key management, 7-8 key pair, creating, 7-10 keytool utility, B-10 KToolbar advanced conguration options, 3-12 application directory, 3-12 starting, 1-1, 2-1 ktools.properties, 3-12, C-1
G
GCD le, 7-6
H
heap size, 4-7 -help option, B-4
L
landmarks, 14-3 libraries, 3-8 locale, 18-1, 18-3 location, 14-1 landmarks, 14-3 provider, 14-3 LX260, A-34
I
identied_third_party protection domain, 7-4 -import command, B-10
J
JAD, 2-9 attributes, 3-3 creating, 2-9 MIME type, 2-20 JAD attributes, 6-8 JAR creating, 2-9 MIME type, 2-20 Java Card simulator, 15-2 Java Cryptography Extension (JCE) keystore, B-10 javac.encoding property, C-2 JSR 75, 11-1 JSR 82, 12-1 JSR 135, 9-1 JSR 172, 13-1 JSR 177, 15-1 JSR 179, 14-1 JSR 180, 16-1 JSR 184, 10-2 JSR 185, 7-3 JSR 205, 8-1 JSR 226, 10-1 JSR 229, 17-1 JSR 234, A-7 JSR 238, 18-1 JSR 75, 11-1 JTWI protection domains, 7-4
M
M3G, 10-2 managing certicates from command line, B-10 manifest le, creating, B-3 manufacturer protection domain, 7-4 maximum protection domain, 7-4 media capture, 9-2 media formats, 9-1 memory monitor, 5-5 messages, sorting, 5-11 messaging, network simulation, 8-2 method proling, 5-1 microedition.encoding property, C-2 MIDlets in projects, 3-5 signing, 7-12 MIME types, 2-20 minimum protection domain, 7-4 MMAPI, 9-1 Mobile 3D Graphics, 10-2 Mobile 3D Graphics API, 10-1 Mobile Media API (MMAPI), 9-1 capture, 9-2 formats and protocols, 9-1 muglet, 19-4
Index-2
N
network monitor, 5-9 ltering, 5-11 sorting, 5-11 sorting messages, 5-11
O
OBEX demo, A-49 preferences, 12-1 obfuscation, 2-15 installing ProGuard, 2-16 installing RetroGuard, 2-16 Open With, 2-6 open with, 2-5, 4-15 optional APIs, 1-4
creating, 2-2 deploying on real devices, 2-12 libraries, 3-8 MIDlets, 3-5 opening in IDE, 2-13 packaging, 2-9 push registry, 3-7 running, 2-7 selecting APIs, 3-1 source code, 2-3 protection domain JTWI, 7-4 protection domains, 7-1 proxy servers, 4-6 push registry, 3-7
R
remotely-deployed applications, 2-20 resource, add, 4-16 resume, 4-10 revision control, 3-13 Revision Control System (RCS), 3-13 RevisionControl property, 3-13 run options, B-4 Run via OTA, 2-10, 7-3 running, from command line, B-4
P
packaging example from command line, B-3 packaging from command line, B-3 pause, 4-10 pausing and resuming, 4-10 payment API, 17-1 attributes, 17-4 console, 17-7 preferences, 17-4 settings, 17-1 transactions, 17-5 performance, 4-8 permissions, 7-1 persistent storage, 4-7 Personal Information Management (PIM) API, 11-1 phone number, setting in emulator, 8-1 PIM AP, 11-3 preverifying, 2-7 example from command line, B-2 proler, 5-1 call graph, 5-3, 5-4 projects, 2-1, 3-1 attributes, 3-3 building, 2-6
S
SATSA, 15-1 secondary screen, 6-1, 19-1 signed MIDlet suites, 7-1 signing MIDlet suites, 7-5 SIP, 16-1 SMS binary message, sending, 8-5 SMS text message, sending, 8-4 source code location, 2-3 source le, add, 4-16 Sprint certicate database, 7-3 supported APIs, 1-4
T
target platform, 3-3 Tracing, 5-12 tracing options, B-5
Index-3
U
unidentied_third_party protection domain, 7-4 untrusted protection domain, 7-4
V
version control, 3-13 -version option, B-4
W
Wireless Messaging API (WMA), 8-1 Wireless Toolkit certicate manager utility, B-1 running from command line, B-1 Wireless Toolkit, setting locale, C-1 WMA console, 8-3 receiving messages, 8-8 wtk.locale property, C-1
X
-Xdebug option, B-5 -Xquery option, B-5 -Xrunjdwp option, B-5 -Xverbose option, B-5
Index-4