VoIP settings are read directly from an XML file that includes a VoIP Profile a SIP Profile and associated NAT/Firewall settings.
A sample XML file can be downloaded from here. Prior to making or receiving calls, VoIP MIDlets are required to follow two key steps in order to retrieve the VoIP settings and register with the VoIP server:
The XML file needs to be read from the resource (JAR file) and be converted to a String.
String settings = readSettingsFile("/voip_settings.xml");
There is no built-in method available, hence the developer needs to write his/her own method. Given below is an example of a custom made method for reading the XML file:
private String readSettingsFile(String filePath) throws IOException { byte[] fileData = null; InputStream iStream = getClass().getResourceAsStream(filePath); int fileSize = iStream.available(); if (fileSize > 0) { fileData = new byte[fileSize]; iStream.read(fileData, 0, fileData.length); iStream.close(); } return new String(fileData); }
A VoIP Settings instance is needed to read the VoIP settings from the String. When the settings are written, with the built-in writeVoipSettings method, the client attempts to use the settings as provided by the developer to connect and register with the VoIP server. A VoipSettingsStateUpdated listener is used to check the status of the registration attempt, e.g. whether the client is online, offline or if a connection or registration error has occurred:
VoipSettings voipSettings = VoipManager.createVoipSettingsInstance(); voipSettings.setVoipSettingsStateListener(new VoipSettingsStateListener() { public void voipSettingsUpdated(int state, int cause) { /* * this is triggered when registration of VoIP client * completes with the VoIP server or a registration error * occurs */ } }); voipSettings.writeVoipSettings(settings);
For a list of states and causes see the VoIPStates and VoIPCauses class description respectively
For further information see: