Write mobile app with Java Motorola Ideen
Wang Sen Taiwan Jiaotong University Science and Technology Management Institute moli.mt88g@nctu.edu.tw█ preface
All operations in this article are tested on the Windows 200 operating system. If you verify this text on a different platform, such as Windows 98 or Windows Me, we cannot guarantee that there will be the same results.
█ introduction
I don't know when I start, we suddenly feel that the people around you have a mobile phone. Using mobile phones to communicate with others into part of our lives. The people of certain advanced countries in Nordic can use mobile phone to purchase the goods sold by vending machines; they can also use mobile phones as a certification tool when they are engaged in Action Business (M-Commen). Many additional features of the mobile phone in Japan are part of young people culture. The upcoming 3G, wireless broadband, a beautiful dream, brought people to the future of wireless communication.
Then, some vendors start selling their own PDA, as if there is no PDA in hand, it is not like modern people. A wide variety of PDA floods the market, sell well and not sell well, makes people look. At this time, a big problem is generated - we have a very troublesome thing to carry your mobile phone and PDA - even if they are still light and short. If you can combine your mobile phone and PDA, isn't it more convenient? So I heard the manufacturer of consumer's voice, starting with products that launch mobile phones and PDAs, from NOKIA 9000, Motorola A6188 (Tai Chi), to recent The Ericsson R380, Nokia 9210, is an example of a combination of mobile phones and PDAs, although because of the price of the price, these products are still high-order products that many people dream of.
Despite the emergence of PDA combined with mobile phones, we still feel that everyone must find that the application is insufficient, although mobile phones and PDA combine, but the PDA function on these products seems to die. of. We can use C / C on PLMOS, Windows CE, EPOC, etc. to write applications on these platforms on PDA, but have never had a chance to download us on these mobile phones (even The PDA of the phone is also using EPOC, such as Ericsson R380).
I believe that the manufacturer also heard the voice of the engineer who likes to write the program everywhere, so since the end of 2000, there will be many mobile phones that support Java's mobile phones will be launched. Of course, these manufacturers also offer the development procedures on the mobile phone. SDK, we can finally write some small programs to your mobile phone! This is the dream for a long time.
The diversity and complexity of the mobile phone platform can be said to be more than the PDA, so everyone can know - Ha! It's a Java sent a time. We all know that the Java program executed on the browser is called Applet, the Java program executed on Palmos is called Spotlet, but the application executed on the phone we call MIDlet, I believe that everyone is a strange noun, this It is also the protagonist to introduce this article.
Support Java's mobile phone model is known to have Nokia (expected to launch a mobile phone NOKIA 9210 that supports Java in early 2001), Motorola (will first support Java on mobile phones that support Integrated Digital Enhanced Network (IDEN) network, then then A GSM mobile phone that supported Java has been launched. The company's mobile phone will receive Java in 2002 and NTT DoCoMo (will launch mobile phones that support Java in the second quarter of next year).
Although these big companies are ready to support Java, only when deciding this article, only Motorola is open to the website on the website for the program developer download test, so this article is based on Motorola J2ME SDK. Due to the unable to achieve these mobile phone markets, our procedures are implemented in the simulator attached to the SDK. I believe that when these mobile phones are listed, the MIDlet we have written should be easily and successfully executed on Motorola's mobile phone. Talented. ■ How to get Motorola J2ME SDK, the first thing we have to do is Of course, I will still get SDK Luo! Please go directly to https://commerce.motorola.com/idenonline/ideveloper/ download Motorola J2ME SDK Drop 7. If you are not a member of Iden® Developer, please register (free) on the network. After the registration is successful, Motorola will send the password into your Email mailbox and then use the password to log in to my development center on the web page. After entering, you will choose the web page to enter the web page of the downloadable development tool. Please select Motorola J2ME SDK Components Developer Edition. Downloads below DROP 7.0, the download super-connected SDK, the size of the entire SDK is about 3 MB.
Please note the Download Page for Motorola J2METM SDK installation before downloading, you will tell you the installation password, please refer. Time to install Motorola J2ME SDK on your computer, you will ask you to install your password, so be sure to write down this password. █Motorola J2ME SDK installation
Installation requirements According to official needs, install the basic equipments of Motorola J2ME SDK: Pentium 100 MHz Microprocessor 64 MB RAM Windows NT Workstation 4.0 Metallic Pack 3 / Win98 (this article is tested on Windows 2000 Professional Chinese version) about 6 MB Hard disk space Java 2 SDK 1.2.2 (This article uses Java 2 SDK 1.3.0_01 Test) Installing Motorola J2ME SDK Before you install the new Motorola J2ME SDK, please confirm that you have completely deleted the old Motorola J2ME SDK. You can delete the old Motorola J2ME SDK by the "New / Remove Programs" in the console. Then you can clean the old Motorola J2ME SDK installed. Unlock the zip file you downloaded from the Motorola website, you will see a file called Motorola_SDK.exe, you can start the installation action on this file. Note that the system will be required to enter a password when installing, please enter the previously recorded installation password.
█Motorola J2ME SDK directory structure
After you successfully install Motorola J2ME SDK, its directory structure is as follows:
█MIDLET program structure
Programs executed on your phone We collect MIDlet, and its program structure is simple, and the familiar Applet structure has the same integrity. Each MIDlet program must inherit the Javax.microedition.midlet.mIdlet category, and do three functions, which are: protected void startapp () protected void pointsapp () protected void destroyApp () Protected Void DestroyApp (Boolean Unconditional) and a MIDlet program The start of the start and the end of the next step below:
■ Write and compile MIDlet
Please first go to your DEMO / MIDLETS directory under your Motorola J2ME SDK installation directory, and the content named hellomidlet.java is: hellomidlet.javaimport javax.microedition.lcdui. *; Import javax.microedition.midlet. * ; public class HelloMIDlet extends MIDlet {HelloMIDlet () {} protected void startApp () throws MIDletStateChangeException {} protected void pauseApp () {} protected void destroyApp (boolean unconditional) throws MIDletStateChangeException {}} in the demo / midlets directory you'll see To a batch file called CompileAll.bat, it is mentioned earlier that this batch file can also simplify your own MIDlet compilation procedure in addition to the compilation of all in-place example programs. Enter: CompileAll Hellomidlet.java If you successfully compile, the result of the output on the screen is shown below: From the output on the screen, you can find it, let MIDlet can be executed on your phone, generally still have two Action (Similar to Spotlet), compiled and preverqing. For pre-review this action, the author has already mentioned the readers in the Run! PC November, "using the Java Writing Palmos Application Basic Articles", if you have questions about this, please Run! PC November number turned out! From this short MIDlet production process, I believe that everyone can find that the spotlet that can be performed on KVM compared to pure SUN's CLDC can be simply simple. The reason is that compileAll.bat This batch file helps us do most of Dirty Work. That, if you write a good program is not placed in the Demo / MIDlets directory, is it unable to compile? From CompileAll.bat, we can find it to help us complete the above two jobs. If we write a good program to place outside the Demo / MIDlets directory, you can perform the following instructions, you can still make MIDlet: (We assume your Motorola J2ME SDK installed in the D: / MOSDK directory, and Place the hellomidlet.java written in your own D: /JDK1.3.0_01/MY directory. At the same time, we assume that you perform the following instructions under the D: /JDK1.3.0_01/MY directory.) Compile:
Javac -o -bootclasspath d: / motosdk / lib hellomidlet.java Note: -bootclasspath points to the location of the class function library.
Pre-audit:
D: / motosdk / bin / preverier -classpath d: / motosdk / lib ;. -d. hellomidlet Note: 1. -classpath points to the location of the class function library, but also points to the location of the MIDlet we have written. 2. -D pointing to the path you want to pre-compiling the class file, if you write "." Indicates this directory, override the originally compiled class file. If you are not specified, the preset value is "./output" directory.
Of course, if you are troublesome to manually, you can copy CompileAll.bat to other directories, and change its compile instructions to be related to the relevant settings related to the pre-audit instructions and class function libraries. When it comes to CompileAll.bat, the reader will explain to the readers. In the previous mention, CompileAll.bat can help you compile all the sample programs located in the Demo / MIDlets directory, you only need to enter directly under the list: CompileAll . CompileAll.bat will automatically use Package for your compile: com.mot.j2me.midlets.bounce com.mot.j2me.midlets.motests com.mot.j2me.midlets.paddleball com.mot.j2me.midlets. Scribble com.mot.j2me.midlets.tests com.mot.j2me.midlets.tutorials If you want CompileAll.bat to automatically compile out the program under other packages, please turn on CompileAll.bat to modify its CompileClass environment variable setting I.e. ■ After modifying and executing the MIDlet write program, everyone's most hoped thing is to let it execute on the mobile phone, but because you can't get Motorola's mobile phone, we can only attach to the simulator included in Motorola J2ME SDK. Execute our written MIDlet. When I believe that the phone is officially launched, it should be able to perform on the phone smoothly. At the bottom of the author, tell you how to use the simulator included in Motorola J2ME SDK to test the MIDlet you wrote. Before this, because the sample program we have written is just a simple MIDlet empty housing, we must make it possible to display some information on the simulator, so modify the previous program example, so that its content is as follows: Hellomidlet .javaimport javax.microedition.lcdui *;. import javax.microedition.midlet *;. public class HelloMIDlet extends MIDlet {private Display firstDisplay; private Form firstForm; HelloMIDlet () {firstDisplay = Display.getDisplay (this); firstForm = new Form ( "Hello MIDlet"); StringItem firstStrItem = new StringItem ( "Hello", "MIDlet"); firstForm.append (firstStrItem);} protected void startApp () throws MIDletStateChangeException {firstDisplay.setCurrent (firstForm);} protected void pauseApp ( ) {} Protected void destroyApp (Boolean Unconditional) THROWS MIDLETSTATECHANGEEXCEPTION {}} Please place this file in the / demo / midlets directory. After the compilation is completed, switch the directory to the Scripts subdirectory, and you will find some write batch files in this directory. These batch file instructions are executed in this directory to start the simulator. The execution instructions and execution results are as follows:
Directive: Runemul Hellomidlet output result
Directive: Runmotoi1000 Hellomidlet output result instruction: Runmotoiden Hellomidlet output results
Directive: RunStartac Hellomidlet output result
Directive: RunmyDevice Hellomidlet output results error loading property file: c: /properties/myDevice.props (The system can not find the specified path.) The error message will be because you do not specify the appearance of the phone that belongs to the user's customs. Will you teach you how to set your user-keep mobile phone appearance.
If we will write a good program to the Demo / MIDlets directory, you can perform the following instructions, can still start the simulator and perform MIDlet: (We assume your Motorola J2ME SDK installation in d: / motosdk directory Among them, the Hellomidlet.java written in your own is placed in the D: /JDK1.3.0_01/MY directory. At the same time, we assume that you perform the following instructions at the D: /JDK1.3.0_01/MY directory.) Execute Simulator
Java -djava.library.path = d: / motosdk / lib -classpath d: /motosdk/bin/emulator.jar; d: /motosdk/bin/configtool.jar com.mot.tools.j2me.emulator.emulator
-CLASSPATH.; D: / MOSDK / LIB JAVAX.MICROEDITION.MIDLET.AppManager Hellomidlet
-JSA 1 1
Please note: The first -classpath setting, the -classpath and the path name have spaces. The second -classpath setting, there is no space between -classpath and path name.
Execute the simulator and set the i1000 mobile phone appearance
Java -djava.library.path = d: / motosdk / lib -classpath d: /motosdk/bin/emulator.jar; d: /motosdk/bin/configtool.jar com.mot.tools.j2me.emulator.emulator
-CLASSPATH.; D: / MOSDK / LIB -DEVICEFILE resources / motorolai1000.propsjavax.microedition.midlet.Appmanager Hellomidlet-JSA 1 1
Please note: The first -classpath setting, the -classpath and the path name have spaces. The second -classpath setting, there is no space between -classpath and path name.
Execute the simulator and set the appearance of the Iden mobile phone
Java -djava.library.path = d: / motosdk / lib -classpath d: /motosdk/bin/emulator.jar; d: /motosdk/bin/configtool.jar com.mot.tools.j2me.emulator.emulator
-CLASSPATH.; D: / MOSDK / LIB -DEVICEFILE resources / motorolaidenplatform.propsjavax.microedition.midlet.Appmanager
Hellomidlet-JSA 1 1
Please note: The first -classpath setting, the -classpath and the path name have spaces. The second -classpath setting, there is no space between -classpath and path name.
Execute the simulator and set the appearance of the Startac phone
Java -djava.library.path = d: / motosdk / lib -classpath d: /motosdk/bin/emulator.jar; d: /motosdk/bin/configtool.jar com.mot.tools.j2me.emulator.emulator-classpath D: / MOSDK / LIB -DeviceFile Resources / Startac.Propsjavax.microedition.midlet.AppManager
Hellomidlet-JSA 1 1
Please note: The first -classpath setting, the -classpath and the path name have spaces. The second -classpath setting, there is no space between -classpath and path name.
Execute the simulator and set up the user's customs
Java -djava.library.path = d: / motosdk / lib -classpath d: /motosdk/bin/emulator.jar; d: /motosdk/bin/configtool.jar com.mot.tools.j2me.emulator.emulator
-CLASSPATH.; D: / MOSDK / LIB -DEviceFILE
Hellomidlet-JSA 1 1
Please note: The first -classpath setting, the -classpath and the path name have spaces. The second -classpath setting, there is no space between -classpath and path name. If you put your Props file under the Resources directory of the D: / MOSDK / BIN, the above instructions are changed as long as the -devicefile resources /
Note that when you use the above instructions to start the simulator, if you appear Error Information: Error Loading Property File: Resources / DefaultDevice.props (The system can not find the specified path.) This is because you didn't D: / Motosdk / The Resources subdirectory under the bin directory is copied to the D: /JDK1.3.0_01/MY directory. ■ Debugging MIDlet
When writing a Spotlet on Palmos, we can use the System.out.Println () to help us print some messages to help debug, the midlet on your phone? In principle, we can still use System.out.Println () The function is some output. When the simulator is executed, some messages are output on the command column. Also, on Palmos, Kvmutil.PRC can help our records output from the record. On the phone? Because there is no practical machine to test, this problem is still unknown now, I believe that Motorola will have a complete solution! In the instruction file attached to Motorola J2ME SDK, it is roughly When you go to debug, it is mentioned that if we want to debug on-device debugging, you must meet a few conditions:
The machine itself must have commissioning and compatible with KDWP (KVM Debug Wire Protocol). Because of debugging, debugging tools need to use KDWP and machines to obtain debug information. Manufacturing vendors themselves provide a way to download MIDlet to mobile phone for debugging. Provides a tool for MIDlet debugging, which must support the mobile phone that is used when using KDWP debugging (eg serial port or UDP).
Well, it seems that it is very convenient to write, and the MIDLET program should be very convenient. █Motorola J2ME SDK support for Chinese
I believe I have seen the readers of Run! PC November, "using Java Write a Palmos Application Basics", you will have problems in Chinese that cannot be displayed normally when writing the spotlet on Palmos. Chinese issues are divided into two parts, one is a Chinese problem on the user interface, one is the Chinese problem on the output of the command (using the output of the system.out.println (), please do a small experiments, we need to write the program in front of the following changes: HelloMIDlet.javaimport javax.microedition.lcdui *; import javax.microedition.midlet *; public class HelloMIDlet extends MIDlet {private Display firstDisplay; private Form firstForm; HelloMIDlet () {.. FirstDisplay = display.getdisplay (this); firstform = new form ("Haro! MIDlet"); StringItem firstStritem = New StringItem ("Haro", "Midley"); Firstform.Append (FirstStritem); System. out.println ( "MIDlet start");} protected void startApp () throws MIDletStateChangeException {firstDisplay.setCurrent (firstForm);} protected void pauseApp () {} protected void destroyApp (boolean unconditional) throws MIDletStateChangeException {}} the present MIDlet compiled After the pre-audit, we turn on the simulator to perform this MIDlet, under the execution result:
User Interface Output: Command Column Output
We have found that the preset compilation instruction will allow the user interface to output Chinese normally, and the command column cannot output the correct Chinese.
We have found that the preset compilation instruction will allow the user interface to output Chinese normally, and the command column cannot output the correct Chinese. Then please change the original instruction javac -bootclasspath ../../lib% compileclasspath ../../lib% compileclasspath ../../lib% compileclasspath ../../lib% compileclasspath ../../lib% compileclasspath ../../lib% compileClassPath. This MIDlet executes results:
User Interface Output: Command Column Output
We have found that the preset compilation instruction will make the user interface to output Chinese normally, but the command column can output the correct Chinese.
This result is different from the Chinese test results made on PALMOS. If you write a Spotlet if you use Javac. . . When the command, you will find that the user interface output on the simulator is garbled, but the output on the command column can output Chinese normally. But if you are using Javac -Encoding ISO8859_1. . . Instructions, then the user interface output on the CLDC in the simulator is output or the output on the command column turns garbled. It is not possible to output Chinese (this part is because the CLDC is fully attached to the simulator, resulting in actual machinery The result is different). In short, if the spotlet you have written cannot be output in the actual machine or POSE installed on the Chinese system, you can also add -Encoding ISO8859_1 in the compile instruction, you can see normal machine or pose. Chinese word. This problem will be generated, mainly because of the compiled Java class file (Byte code), all text codes use UTF8. For example, when you use the "Start" in the program code, the BIG5 encoding of the word "start" is B1D2. The BIG5 encoded of "moving" this is B0CA. We will use Javac XXXX.java to compile the original code to generate class files. In fact, this line of instructions is equivalent to Javac -Encoding "Big5" xxxx.java under the Windows environment of traditional Chinese. That is, when the compiler reads the Chinese characters of the BIG5 encoding range, the BIG5 code will be automatically converted to Unicode, which means that after the table, "start" this The word Unicode encoded is 555F. The Unicode encoded of the word "moving" is 5272. Then use the UTF8 encoding to turn this Unicode to UTF8, stored in class files, so if you view class files with a text editor such as UltraEdit, you will see, "from" UTF8 encoding is E5959F. The UTF8 encoding of the word "moving" is E58B95. Next, when we want to output Chinese when execution, the JVM will be responsible for reading the UTF8 code, then transfer it to Unicode, and finally convert BIG5 based on the encoded encoded according to the system environment you are using, and then output to the screen on. However, after the test results, KVM seems to only read UTF8, and output it directly after converting back to Unicode. Less turn back to BIG5 steps, so the operating system is handled by Unicode as a BIG5, which naturally does not find the Chinese words corresponding to the code, and therefore outputs a bunch of symbols of a bunch of ?????. This is also what we have made in Palmos, even if we installed Chinese systems. OK, since KVM only helps us do half of the work, then, then we will do it, we will still keep the BIG5 encoding method, so we use the instruction javac -Encoding ISO8859_1 XXXX.java, Please do not deepen the two BYTEs encoded in the program code as one (because it is considered to be integrated) work), as long as Chinese is as a normal Western European alphabet set Therefore, when we use the above instructions, you will find Chinese turned into the class file, "start" UTF8 encoded as C2B1 C392. The UTF8 of the word "moving" is encoded as C2B0 C38A.
You can find that the compiler uses the B1, D2, B0, CA as a code as a code. Thus, when KVM reads this encoding, they will turn them back to B1D2 and B0CA, and then the KVM is directly output, it can be used normally. Finally, the entire problem will be summarized, and the author's inferior, the simulator included in the CLDC does not use Javac -Encoding ISO8859_1 XXXX.JAVA instructions, which will make the command column to garbled, which is the normal result, and Motorola J2ME SDK The reason why the user interface in the internal attachment simulator is no problem, it is likely to be just because the simulator operation is different. Therefore, according to the output of KVM, it is likely that we must add the "" I must export Chinese in the actual mobile phone! Special thanks to the Tang Yulong, which is the Department of Seiiti University, ISO, Kailung.tang@msa .hinet.net) classmates. Because the author after he was a warm discussion, we can have more in-depth understanding of the Chinese issue of J2ME █ Support Motorola J2ME SDK development tools.
When writing this article, the integrated development environment (IDE) that supports MIDlet development is only available in the CodeWarrior in the file included in Motorola J2ME SDK. Believe other vendors, such as Borland, should also quickly use its product JBuilder's OpenTools API to support MIDlet development, not to mention Borland JBuilder currently has spotlet solutions. Because the author can't get the CodeWarrior test, you can't provide you with yourself. I believe that if there is a chance, you will have a special manner to introduce you how to use CodeWarrior to write MIDlet. Motorola J2ME SDK comes with the part of the appendix to make a simple introduction to the use of CodeWarrior developed MIDlet, I believe it is quite enough for beginners. Assisted Development Tools included in █Motorola J2ME SDK
In Motorola J2ME SDK, there are three auxiliary development tools, which can facilitate our program development work, and they are:
The J2ME Simulator (J2ME Emulator) allows you to simulate Motorola to support J2ME mobile phone devices on your PC. This can be directly tested on the PC directly on the PC. Bytecode Verifier This validator is used to verify Bytecode in the classfile, which is not illegal to the memory. And confirm that all thections made by the type file loaded into the virtual machine are in line with the Java Virtual Machine Specification. Configuration Editor allows you to create or modify Device Profile.
In the documentation included in Motorola J2ME SDK, the three tools have been described in detail, and the author will not go to it later. █ summary
Call! Good tired, finally arrived at this summary! Do you think that MIDLET is ended like this? No! MIDlet also has a lot of fun! We will explore more in the article after this series. MIDLET. Let's see it next time. ■ Appendix: Sample Procedure