0

我想创建一个使用推送注册表功能自动启动的 MIDlet

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

以下是我提出的代码,由于它没有以任何方式响应任何消息,因此找不到问题。

PS 我知道动态注册需要我先运行一次应用程序。

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();
            }

    }
}
4

1 回答 1

1

当我将此行替换为时,您的代码PushRegistry.registerConnection("sms://:50000",this.getclass().getname, "*"); 有效PushRegistry.registerConnection("sms://:50000",<actual name of the class>, "*");

于 2012-09-16T08:45:05.700 回答