Question

I want to create a MIDlet which automatically starts using push registry function

PushRegistry.RegisterConnection("sms://:50000", this.getclass().getname(),"*");

Following is the code which I have come up with, and cannot find the problem with it as it is not responding in any way to any message.

P.S. I am aware of the fact that dynamic registration requires me to first run the app once.

public class Midlet extends MIDlet implements CommandListener,Runnable {

    private Display disp;
    Form form = new Form("Welcome");
    Command ok,exit;


    public void startApp() {
        String conn[];
         exit= new Command("exit",Command.CANCEL,2);
         ok= new Command("ok",Command.OK,2);
         form.addCommand(ok);
         form.addCommand(exit);
        form.setCommandListener(this);
        conn = PushRegistry.listConnections(true);
        disp=Display.getDisplay(this);
        disp.setCurrent(form);

            form.append("Midlet");       
            form.append("Press OK to register sms connection");


    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
         notifyDestroyed();
    }

    public void commandAction(Command c, Displayable d) {
        if(c.getLabel().equals("exit"))
        {
            System.out.println("exit pressed");
            destroyApp(true);
        }
        if(c.getLabel().equals("ok"))
        {
            String[] cn;
            cn=PushRegistry.listConnections(true);
            form.append(""+cn.length);





            for(int i=0;i<cn.length;i++)
            {
                form.append(cn[i]);
            }
                Thread t = new Thread(this);
                t.start();
        }
    }

    public void run() {
        try {       
                PushRegistry.registerConnection("sms://:50000",this.getclass().getname, "*");
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            }

    }
}
Was it helpful?

Solution

Your code worked when I replaced this line PushRegistry.registerConnection("sms://:50000",this.getclass().getname, "*"); with PushRegistry.registerConnection("sms://:50000",<actual name of the class>, "*");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top