×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    45

    Exclamation push registry-midlet does not start automatically

    hi there
    i want to build a midlet which listens for sms on port 16013 and when there is a sms on that port then the application should launch automatically and then send back sms to the predefined subscriber. for this i have used push registry. i had problem running that application and even tried the code from the nokia snippet.
    while running the application i registered the port from the menu and then exit the application without un-registering the port. but whenever i send sms to that application port using the other gsm, the edge sign gets crossed for a while resembling the arrival of sms. but after that there is no sms and no any other notification. the execution of the application is expected at this stage.
    i even defined permission for push registry,sms send and sms receive and installed application using jad.
    i am testing this application on 6303,3110,5130. all have the same problem.
    please correct me where i am wrong so that application is not starting. do i need to sign my application?????
    any helps will be appreciated

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    45

    Re: push registry-midlet does not start automatically

    I used the following code:
    Code:
    public class StubMIDlet extends MIDlet implements CommandListener,
            MessageListener {
        private Display display;
        private Form mainForm;
        private TextField logField;
        private DataOutputStream logStream;
        private final String LOG_PATH;
        private static final String LOG_FILE = "JavaMEStubLog.txt";
        private final String MIDLET_CLASS_NAME;
        private static final String SMS_CONNECTION_URL = "sms://:16013";
        private static final String ALLOWED_SENDER_FILTER = "*";
        private static final Command EXECUTE_COMMAND =
                new Command("Execute snippet", Command.ITEM, 0);
        private static final Command EXIT_COMMAND =
                new Command("Exit", Command.EXIT, 0);
        private static final Command REGISTER_CONNECTION_COMMAND =
                new Command("Register connection", Command.ITEM, 0);
        private static final Command UNREGISTER_CONNECTION_COMMAND =
                new Command("Unregister connection", Command.ITEM, 0);
        private static final Command REGISTER_TIMER_ALARM_COMMAND =
                new Command("Register timer alarm", Command.ITEM, 0);
        private Vector availableConnections = new Vector();
        public StubMIDlet() {
            LOG_PATH = System.getProperty("fileconn.dir.photos");
            MIDLET_CLASS_NAME = this.getClass().getName();
            display = Display.getDisplay(this);
            setupMainForm();
            setupLogFile();
        }
        private void setupMainForm() {
            mainForm = new Form("StubMIDlet");
            logField = new TextField("Log", null, Short.MAX_VALUE, TextField.PLAIN);
            mainForm.append(logField);
            mainForm.addCommand(REGISTER_CONNECTION_COMMAND);
            mainForm.addCommand(UNREGISTER_CONNECTION_COMMAND);
            mainForm.addCommand(REGISTER_TIMER_ALARM_COMMAND);
            mainForm.addCommand(EXIT_COMMAND);
            mainForm.setCommandListener(this);
        }
        private void setupLogFile() {
            String fcVersion =
                System.getProperty("microedition.io.file.FileConnection.version");
            if (fcVersion == null) {
                printString("The device doesn't support file logging.\n" +
                        "Log output is not available.");
                return;
            }
            try {
                FileConnection fconn =
                        (FileConnection)Connector.open(LOG_PATH + LOG_FILE);
                if (!fconn.exists()) {
                    fconn.create();
                }
                logStream = fconn.openDataOutputStream();
                fconn.close();
            } catch (IOException ex) {
                printString("The log file could not be set up.\n" +
                        "Log output is not available.");
                return;
            }
        }
        private void executeSnippet() {
            String text = "Snippet executed";
            printString(text);
            try {
                logPrintString(text);
            } catch (IOException ex) {
                printString(ex.getMessage());
            }
            displayNote(text);
        }
        private void registerSMSConnection() {
            printString("Registering the connection...");
    
            try {
                PushRegistry.registerConnection(SMS_CONNECTION_URL,
                        MIDLET_CLASS_NAME, ALLOWED_SENDER_FILTER);
                printString("Registration is complete!");
                // Update the inbound connections
                clearConnections();
                getPushRegistryConnections();
            } catch (ClassNotFoundException ex) {
                printString(ex.toString());
                printString("Registration failed.");
            } catch (IOException ex) {
                printString(ex.toString());
                printString("Registration failed.");
            }
        }
    
        private void unregisterSMSConnection() {
            printString("Unregistering the connection...");
            PushRegistry.unregisterConnection(SMS_CONNECTION_URL);
            printString("Unregistration is complete!");
        }
    
        private void registerTimerAlarm(long timePeriodToAutoStart) {
            // Set the launch time to current time + the specified period
            long timeToWakeUp = System.currentTimeMillis() + timePeriodToAutoStart;
            printString("Registering the timer alarm...");
    
            try {
                PushRegistry.registerAlarm(MIDLET_CLASS_NAME, timeToWakeUp);
                printString("Alarm is registered!");
            } catch (ClassNotFoundException ex) {
                printString(ex.getMessage());
                printString("Alarm registration failed.");
            } catch (ConnectionNotFoundException ex) {
                printString(ex.getMessage());
                printString("Alarm registration failed.");
            }
        }
        private void clearConnections() {
            if (availableConnections != null) {
                while (!availableConnections.isEmpty()) {
                    MessageConnection messageConnection =
                            (MessageConnection) availableConnections.firstElement();
                    if (messageConnection != null) {
                        try {
                            messageConnection.setMessageListener(null);
                            messageConnection.close();
                        } catch (IOException ex) {
                            printString(ex.toString());
                        }
                    }
                    availableConnections.removeElementAt(0);
                }
            }
        }
    
        private void getPushRegistryConnections() {
            String[] connections;
            connections = PushRegistry.listConnections(false);
            if (connections.length != 0) {
                printString("List of available connections: ");
                for (int i = 0; i < connections.length; i++) {
                    try {
                        MessageConnection mc =
                                (MessageConnection) Connector.open(connections[i]);
                        printString("(" + i + ") - " + connections[i]);
                        mc.setMessageListener(this);
                        availableConnections.addElement(mc);
                    } catch (SecurityException ex) {
                        printString("Connection failed.");
                        printString(ex.getMessage());
                    } catch (IOException ex) {
                        printString("Connection failed.");
                        printString(ex.getMessage());
                    }
                }
            }
        }
        private void displayNote(String text) {
            Alert infoNote = new Alert("Info", text, null, AlertType.INFO);
            infoNote.setTimeout(3000);
            display.setCurrent(infoNote, mainForm);
        }
        private void printString(String text) {
            logField.insert(text + "\n", logField.size());
        }
        private void logPrintString(String text) throws IOException {
            if (logStream == null) {
                return;
            }
            logStream.writeChars(text + "\n");
            logStream.flush();
        }
        private void exit() {
            try {
                if (logStream != null) {
                    logStream.close();
                }
            } catch (IOException ex) {
                printString(ex.getMessage());
            }
            notifyDestroyed();
        }
        public void startApp() {
            // The initial display is the main form
            display.setCurrent(mainForm);
        }
        public void pauseApp() {
            // No implementation required
        }
        public void destroyApp(boolean unconditional) {
            // No implementation required
        }
        public void commandAction(Command command, Displayable displayable) {
            if (command == EXIT_COMMAND) {
                exit();
            } else if (command == REGISTER_CONNECTION_COMMAND) {
                registerSMSConnection();
            } else if (command == UNREGISTER_CONNECTION_COMMAND) {
                unregisterSMSConnection();
            } else if (command == REGISTER_TIMER_ALARM_COMMAND) {
                registerTimerAlarm(30000);
            } else if (command == EXECUTE_COMMAND) {
                executeSnippet();
            }
        }
        public void notifyIncomingMessage(MessageConnection conn) {
        }
    }

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Does another MIDlet send that SMS?

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    45

    Re: push registry-midlet does not start automatically

    Quote Originally Posted by traud View Post
    Does another MIDlet send that SMS?
    Sorry what did you mean by that?

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: push registry-midlet does not start automatically

    You are using dynamic push registry, try using static push and changing the port no. and signing the application it should work.

    thanks,
    ~Amitabh

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    garefield, who sends the SMS for waking-off your MIDlet? Is it another MIDlet (on another device) or non-J2ME code of yours?

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    45

    Re: push registry-midlet does not start automatically

    Quote Originally Posted by traud View Post
    garefield, who sends the SMS for waking-off your MIDlet? Is it another MIDlet (on another device) or non-J2ME code of yours?
    I want and incoming sms to a particular port(from another mobile) to wake up the midlet.

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Yes, but which source code sends that SMS. Is it a MIDlet or something else? A common problem is not to use a MIDlet and/or using the wrong SMS format.

  9. #9
    Registered User
    Join Date
    Nov 2009
    Posts
    45

    Re: push registry-midlet does not start automatically

    well i tried using static push registry i.e i added proper permissions and port number in jad file. i did this using netbeans. even i checked the jad file all are set fine.then i installed the midlet OTA(JAD).
    now when i run the midlet it runs fine, while even running when the second midlet on the second device send sms to that specified port of the midlet the device gets the sms but it digests it, i cannot display the sms message even.
    now after exiting the midlet when again i send the sms on that port with second midlet. it again digest the sms but does not start the midlet either.
    so i am having a great problem,as my message are getting digest i am sure the installation using push registry works but why is the midlet not started. why are all the sms to that port digested.but i can get sms in my inbox when sent to other ports.
    i want to trigger the midlet when sms is found on the particular port.
    as mentioned earlier non of the devices i tested worked.all were the same.i think i am missing something.
    please help me

  10. #10
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: push registry-midlet does not start automatically

    try using this example to listen the SMS:
    http://wiki.forum.nokia.com/index.ph...ronous_version

    change the port no in this or your application and try on many other port numbers.

    With above you should atleast be able to get the port directed SMS to your application.

    thanks,
    ~Amitabh

  11. #11
    Registered User
    Join Date
    Nov 2009
    Posts
    45

    Re: push registry-midlet does not start automatically

    i tried the examples in nokia forum for sending and receiving sms.sending works fine. push registry even works but does not load the midlet,my sent sms is being digested because of push registry.it would be fine to digest the sms if the midlet would have been loaded in that cost.
    please help me getting my midlet launched automatically on receiving sms

Similar Threads

  1. Auto start 6212 and MIDlet suite
    By ivanmilara in forum Near Field Communication
    Replies: 0
    Last Post: 2010-03-09, 15:26
  2. SMS PUSH Registry Problem: Connector.open() throws IOException
    By rexmtorres in forum Mobile Java General
    Replies: 1
    Last Post: 2010-02-26, 01:39
  3. Replies: 4
    Last Post: 2009-07-10, 12:07
  4. Push Registry Midlet Not Invoke Automaticaly
    By rutuja3998 in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2008-05-12, 22:56
  5. Push Registry Problem..SMS Demo
    By dhamodharan in forum Mobile Java General
    Replies: 2
    Last Post: 2005-11-24, 00:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×