In the code below when a sms arrived the String variable alfa change its value, then with a command menu it's possible to view the value of alfa. At startUp alfa is equal to "Nothing"..
The problem is: in my 6600 this midlet doesn't receive nothing...the notifyIncomingMessage method is not called bu platform...why?
import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
public class Spy extends MIDlet implements CommandListener, MessageListener
{
MessageConnection messconn;
String alfa;
boolean done;
Reader reader;
private Display display;
private Command cmExit;
private Command cmHelp;
private Form fmMain;
private TextBox Hello;
public Spy()
{
display = Display.getDisplay(this);
cmExit = new Command("Exit",Command.EXIT,1);
cmHelp = new Command("View Alfa",Command.HELP,1);
fmMain = new Form("SpyGame");
fmMain.addCommand(cmHelp);
fmMain.append("Hello\n");
fmMain.setCommandListener(this);
}
protected void startApp( ) throws MIDletStateChangeException
{
display.setCurrent(fmMain);
alfa = "Nothing";
try
{
messconn = (MessageConnection) Connector.open("sms://:3381");
messconn.setMessageListener(this);
done = false;
}
catch(IOException e)
{
alfa = "StartApp";
}
}
protected void pauseApp( )
{
done = true;
try
{
messconn.close();
}
catch(IOException e)
{
}
}
protected void destroyApp( boolean p1 ) throws MIDletStateChangeException
{
done = true;
try
{
messconn.setMessageListener(null);
messconn.close();
}
catch(IOException e)
{
}
}
public void notifyIncomingMessage(MessageConnection conn)
{
alfa = "Arrived Outside";
if (conn == messconn)
{
alfa = "Arrived";
}
}
public void commandAction(Command c, Displayable s)
{
try
{
if (c == cmExit)
{
destroyApp(true);
notifyDestroyed();
}
else if (c == cmHelp)
{
fmMain.append(alfa);
}
}
catch (MIDletStateChangeException e)
{
}
}

Reply With Quote

