|
|
Classification: |
Java |
Category: |
J2ME MIDP 2.0 |
Created: |
01/12/2005 |
Modified: |
01/17/2005 |
Number: |
FAQ-1206 |
Platform: |
Not Applicable |
|
Question: Can I launch a MIDlet from a native application?
Answer: Yes, this can be achieved by means of the MIDP 2.0 Push Registry. The MIDlet must register itself with the Push Registry in order to be auto-launched in response to an incoming connection.
For example for a MIDlet to be launched in response to an incoming socket connection on port 1234, the MIDlet suite would
include the following entry in the Application Descriptor (JAD) file MIDlet-Push-1: socket://:1234, MyMIDlet, *
This tells the MIDP Application Management System to auto-launch the MIDlet (whose MIDlet class is MyMIDlet) in response to
an incoming socket connection on port 1234, originating from any IP address (* represents the wildcard address). The startApp method contained in the MyMIDlet class may look something like this:
public void startApp() { ... new Thread(){ public void run(){ try { ssc = (ServerSocketConnection)Connector.open("socket://:1234"); SocketConnection sc = (SocketConnection)ssc.acceptAndOpen(); DataInputStream is = sc.openDataInputStream(); ... }catch(Exception e){ //Handle } } }.start(); ... display.setCurrent(messageView); }
Note in line with good MIDP programming practice, handling the incoming connection should be performed in a new Thread to
avoid blocking the MIDP System Event Dispatcher.
So to launch the MIDlet the C++ application simply opens a client socket connection on the local host address (127.0.0.1)
and (for this example) port 1234.
Also see FAQ-1198
|
|
|