Saturday, March 21, 2009

How To : Auto-launch midlets using pushregistry except incoming message

How To Launch midlets using pushregistry other than incoming message through alarm....its very simple ...all you need to do is just register
alarm for a particular time for launching the midlet automatically...
below is the syntax for registering the alarm :

Date alarm = new Date();
String midletClassName = this.getClass().getName();
PushRegistry.registerAlarm(midletClassName, alarm.getTime());

pushregistry.registeralarm method used to register your midlet.

Code:



PushRegistry.registerConnection(defaultURL,midletClassName,
defaultFilter);



Enjoy!

2 comments:

  1. I have used the same way PushRegistry bye using regiserAlarm but it is not launching the Midlet

    The code which i have used is like this-

    public class AlarmMidlet extends MIDlet implements CommandListener
    {
    DateField dateField;
    Form form;
    Command ok;

    public void startApp()
    {
    form = new Form("Welcome");
    ok = new Command ("OK",Command.OK,1);
    form.append("Hello AlarmMidlet");
    form.addCommand(ok);
    form.setCommandListener(this);
    Display.getDisplay(this).setCurrent(form);

    System.out.println("startApp");
    }

    public void pauseApp()
    {

    }
    public void commandAction(Command command, Displayable arg1)
    {
    if(command == ok)
    {

    destroyApp(true);
    }
    }
    public void destroyApp(boolean unconditional)
    {
    try
    {
    String cn = this.getClass().getName();
    // Get the current time by calling Date.getTime()

    Date alarm = new Date();
    PushRegistry.registerAlarm(cn, alarm.getTime() + 10000);//for 10sec
    System.out.println("Time :"+alarm.getTime());
    System.out.println("In try of AlarmMidlet");
    System.out.println("Class Name :"+cn);
    notifyDestroyed();
    }
    catch (Exception exception)
    {
    exception.printStackTrace();
    }
    }

    }

    Please guide me if something is wrong here or i have to do any other setting.
    I completely new in this field.

    ReplyDelete
  2. Please have a look on following KB of article for initial step :

    http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800429/How_To_-_Register_a_MIDlet_with_the_PushRegistry.html?nodeid=817112&vernum=0

    http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800429/How_To_-_Create_an_auto-start_MIDlet_using_the_PushRegistry.html?nodeid=817209&vernum=0

    ReplyDelete

Place your comments here...