Thursday, July 15, 2004

J2ME and my Nokia 7250i

It's been a few years since I did any mobile work (a WAP web site was the last), so I thought I'd have a go at developing a simple application for my Nokia 7250i. Nokia's forums have a lot of good stuff available for developers. For starters the device details page for the 7250i gives details on what Java technology I can access - it appears I need to develop an MIDlet (max 64Kb) that I can then download Over-the-Air (OTA)

An MIDlet appear to be very to an applet in concept. The MIDLet class can be found in the javax.microedition.midlet.* package. Once you have coded your MIDlet application, you can use the Nokia Developer's Suite to generate the .JAR and .JAD (Java Application Description) files. The Nokia Developer's Suite also has an emulator which avoid round-tripping to a real phone. One issue I found with the Nokia Developer's Suite is that it comes with integrationg for Java Forte and JBuilder, but no integration for Eclipse.

The easiest way to get the MIDlet onto your phone is to place the .JAR and .JAD onto a web server, setup MIME tags for .jad and .jar, add a HTML page that links to the .JAD files, and use the Nokia phone to browse to the page, and install the application.

midlet.org and other sites on the web have a load of free applications that you can download.

J2ME code for "Hello World":
package com.First;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class First extends MIDlet
{
private MyCanvas canvas;

class MyCanvas extends Canvas
{
protected void paint(Graphics arg0) {
arg0.drawString("Hello World", 0, 0, Graphics.TOP|Graphics.LEFT);

}
}

public First()
{
canvas = new MyCanvas();
}

protected void startApp( ) throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(canvas);
}

protected void pauseApp( )
{
}

protected void destroyApp( boolean p1 ) throws MIDletStateChangeException
{
}
}

.JAD file for the above application:
MIDlet-Name: MyMIDlet
MIDlet-Version: 0.0.1
MIDlet-Vendor: MyCompany
MicroEdition-Profile: MIDP-1.0
MicroEdition-Configuration: CLDC-1.0
MIDlet-Jar-URL: MyMIDlet.jar
MIDlet-Jar-Size: 2301
MIDlet-1: First, , com.First

0 Comments:

Post a Comment

<< Home