Guide t getting started in J2ME fr the Mtrla A780 phne This guide will take yu thrugh setting up a build envirnment fr J2ME in Windws and in writing a few sample applicatins fr the A780 phne. There are sme ntes at the end if yu are n anther platfrm, but we strngly recmmend using a Windws envirnment s that yu can make full use f the simulatr and debug utput. 1. Setting up Eclipse We recmmend using Eclipse fr yur Java editing. If yu're nt familiar with Eclipse, yu can get mre infrmatin here: http://www.eclipse.rg/ The latest versin f Eclipse can be dwnladed here: http://www.eclipse.rg/dwnlads/dwnlad.php?file=/eclipse/dwnlads/drps/ R-3.1.1-200509290840/eclipse-SDK-3.1.1-win32.zip 2. Setting up the Mtrla J2ME SDK Next, yu'll need t set up the Mtrla SDK. Yu will need t create an accunt n the Mtcder website: https://www.mtcder.cm/mtrla/template.jsp;jsessinid=1efdf:43cd0cee:99 0f451891647ff?filename=center_registratin.jsp Then dwnlad the latest SDK frm: http://www.mtcder.cm/mtrla/dwnlad.jsp?filename=dwnlads/files /SDK542.zip Install this SDK t yur windws system in the default directry (makes later steps much easier!) 3. Setting up EclipseME J2ME Plugin Next, yu need t set up the J2ME plugin that will tie the Mtrla SDK int the Eclipse envirnment. Install EclipseME with these instructins: http://eclipseme.rg/dcs/installeclipseme.html Cnfigure EclipseME with these instructins: http://eclipseme.rg/dcs/cnfiguring.html
4. Creating a simple J2ME applicatin Here's a basic runthrugh n hw t create a simple J2ME applicatin, basically a J2ME hell wrld. 1. Create a new J2ME prject: http://eclipseme.rg/dcs/createprject.html 2. Create a new Midlet in the prject named "HellWrld" A midlet is a J2ME applicatin and represents the main UI class fr a prject. http://eclipseme.rg/dcs/createmidlet.html 3. Yu can use the fllwing surce fr the midlet: Hellwrld.java 4. Yu can debug and install using the installatin instructins belw. 5. Debugging J2ME applicatins in the simulatr This sectin will cver debugging and the use f the M3 simulatr in cnjunctin with Eclipse. It is recmmended that yu try t run applicatins in the emulatr befre trying t run them n the phne. 1. Chse Run... frm the Run menu f ecipse. 2. Under Cnfiguratins, duble click n the header Wireless Tkit Emulatr t create a new cnfiguratin. The prject name shuld be autppulated with yur current prject. Under "Executable: Midlet" enter the name f yur Midlet. 3. Under the emulatin, platfrm definitin tab, chse "Mtrla SDK fr J2ME MOJM3" 4. Click n Run t start the Midlet in the emulatr. T debug instead f run, cmplete the same setup under "debug..." 6. Installing the applicatin n the phne There are tw files needed t install yur J2ME applicatin n the phne. One is the jar file which cntains all f yur cmpiled java cde. The ther is the jad file while cntains metadata abut yur applicatin and permissins infrmatin. Bth f these are generated by Eclipse. T make sure they have been updated prperly befre lading them nt the phne, right click n yur prject name in the Package Explrer and select "J2ME" "Create Package" frm the cntext menu. This will frce a regeneratin f the jar and jad file in the deplyed flder fr yur prject. Make sure yu phne is in USB Mass Strage mde by ging t the main menu, set up, usb mde and chsing "mass strage." Select "save" t exit ut f the settings. Yur phne will nw munt as a USB hard drive when plugged int yur cmputer. Plug in yur phne and pen up a file explrer windw with the newly munted drive. Cpy the jad and jar files frm the deplyed flder f yur prject t the drive. Wait a few secnds and then unplug yur phne. The files are nw in the flash file system f the phne.
Navigate t the flder that yu saved the files t n yur phne by ging t the main menu and pening the "files" applicatin. Click nce n the jad file (NOT the jar file) t install the applicatin. Say k t any dialgs that may appear and chse the main menu grup that yu want the shrtcut t yur new applicatin t appear in. Yu may nw launch yur applicatin frm the main menu by clicking n its icn. Nte: Since yu dn't have a debugging cnsle when yu are running applicatins n the phne, it is recmmended that yu catch all exceptins and call the fllwing methd with the tstring() f yur exceptin: public vid displayexceptin(string e) { Alert a = new Alert("errr:",e,null,AlertType.ERROR); a.settimeut(alert.forever); mydisplay.setcurrent(a,titlescreen); 7. A wrd abut permissins When yu use varius classes in J2ME, yu need t make sure yu set the permissins in yur JAD file apprpriately. Yu can d this by clicking n the JAD file in yur main prject (nt the ne in "deplyed") and ging t the "ptinal" tab. Under "Midlet Permissins:" add the apprpriate permissins cmma separated. The fllwing are cmmn permissins: javax.micreditin.lcatin.lcatin cm.mtrla.file.readaccess cm.mtrla.file.writeaccess javax.micreditin.i.cnnectr.http cm.mtrla.phne javax.wireless.messaging.sms.send javax.wireless.messaging.sms.receive 8. Example cde: 0. HTTP Dwnlad: StringBuffer s = new StringBuffer(); HttpCnnectin c = (HttpCnnectin)Cnnectr.pen("http://web.mit.edu/index.ht ml"); InputStream is = c.peninputstream(); byte b; while ((b = (byte)is.read())!= -1) { s.append((char)b);
is.clse(); c.clse(); Permissins needed: javax.micreditin.i.cnnectr.http 1. Writing t a file: FileCnnectin sc = (FileCnnectin)Cnnectr.pen("file:///phne/tmp.txt"); OutputStream s = sc.penoutputstream(); s.write(("text t g int the file").getbytes()); s.flush(); s.clse(); Permissins needed: cm.mtrla.file.writeaccess 2. Reading a file: FileCnnectin sc = (FileCnnectin)Cnnectr.pen("file:///phne/tmp.txt"); InputStream is = sc.peninputstream(); StringBuffer sfar = new StringBuffer(); byte c; while ((c = (byte)is.read())!= -1){ sfar.append((char)c); is.clse(); Permissins needed: cm.mtrla.file.readaccess 3. Sending an SMS: sender = (MessageCnnectin)Cnnectr.pen("sms://"); TextMessage t = (TextMessage)sender.newMessage(MessageCnnectin.TEXT_MESSA GE); t.setpayladtext(message); t.setaddress("sms://" + cntactnumber); sender.send(t); Permissins needed: javax.wireless.messaging.sms.send 4. Listening fr an SMS: blah Permissins needed: javax.wireless.messaging.sms.receive 5. Getting GPS lcatin: LcatinPrvider lc = LcatinPrvider.getInstance(null); lc.setlcatinlistener(ll,0,-1,-1); Lcatin lcatin = lc.getlcatin(60*3);
String lat = lcatin.getqualifiedcrdinates().getlatitude(); String ln = lcatin.getqualifiedcrdinates().getlngitude(); Permissins needed: javax.micreditin.lcatin.lcatin 6. Getting Cell ID: String cellid = System.getPrperty("phne.cid"); Permissins needed: nne 7. Placing a phne call: Dialer dialer = Dialer.getDefaultDialer(); dialer.startcall("6172531000"); 9. Helper classes Permissins needed: cm.mtrla.phne The fllwing helper classes implement cmmn features f standard desktp java that yu might find useful t use in J2ME: PrpertiesFile.java StringTkenizer.java BufferedInputReader.java Timer.java / TimerListener.java 10. J2ME develping n Linux/Mac While the Mtrla emulatr nly runs n Windws, yu shuld be able t cde J2ME apps n ther platfrms. Sn, we will pst the jar file fr the a780 sdk that yu can link int yur prject in eclipse n any platfrm. 11. Mre cmplete references Mtrla a780 develper guide J2ME In a Nutshell