A VoIP MIDlet can receive calls while active, but it can also register itself with the AMS (Application Management Software) and wake up when a call is received while the device is in idle mode.
When the MIDlet is running, A VoipMTCallListener is used for listening for incoming calls:
VoipManager.setVoipMTCallListener(new VoipMTCallListener() { public void onIncomingCall(int callId) { VoipAudioCall call = VoipManager.createVoipAudioMTCallInstance(callId); call.setVoipAudioCallStateListener(new VoipAudioCallStateListener(){ public void voipAudioCallUpdated(int state, int cause, int callid) { /* * This is triggered when a call is established, terminated * or an error occurs. */ } }); } });
For a list of states and causes see the VoIPStates and VoIPCauses class description respectively.
When the MIDlet is not running, it needs to register with AMS by adding the name of the main instance that extends the MIDlet class to the Application Descriptor as follows:
MicroEdition-Handler-1: com.nokia.example.voip.VoIPExample, application/vnd.nokia.voip.audio.call
Note that the full package path needs to be used, e.g. in the example above the main MIDlet class is called VoIPExample and can be found within the com.nokia.example.voip package.
The getAppProperty method is used from the instance that extends the MIDlet class to retrieve the invocation reason (“arg-0”) and the caller id (“arg-1”). Developers need to check if the invocation reason is a valid incoming call and then handle the incoming call as follows:
String invokeReason = classThatExtendsMIDlet.getAppProperty("arg-0"); if (invokeReason.equals(VoipManager.VOIP_MT_CALL_ALERTING) || invokeReason.equals(VoipManager.VOIP_MT_CALL_WAITING) { System.out.println("MIDlet launched due to an incoming call"); try { int callId = Integer.parseInt(this.getAppProperty("arg-1")); // handle here the incoming call } catch (NumberFormatException e) { System.out.println("Invalid call ID!"); } }
Handling the incoming call requires the same steps as provided in the onIncomingCall method, i.e. creating a VoIPAudioCall instance and adding a VoipAudioCallStateListener.