Example of Android application for audio calls

On the screenshot below the example is displayed when a call is established.

In the input field 'WCS URL', 192.168.2.104 is the address of the WCS server.
In the input field 'Callee', 001 is the SIP username of the callee.

SIP connection is established/closed when Connect/Disconnect button is clicked.
Call is placed/terminated when Call/Hangup button is clicked, and put on hold/retrieve when Hold/Unhold button is clicked.

Work with code of the example

To analyze the code, let's take class PhoneMinActivity.java of the phone-min example version with hash 4ed4c6d77, which can be downloaded with corresponding build 1.0.1.3.

1. Initialization of the API. line 71

Flashphoner.init(this);


For initialization, object Сontext is passed to the init() method.

2. Connection to server.

Session for connection to server is created when Connect button is clicked. line 223

session = Flashphoner.createSession(sessionOptions);


Session is created with method createSession(), to which object SessionOptions (line 222) with URL of WCS server is passed.

Callback functions for session events are added (line 224)

session.on(new SessionEvent() {
    public void onConnected(final Connection connection) {
        .....
    }
    public void onRegistered(final Connection connection) {
        .....
    }
    public void onDisconnection(final Connection connection) {
        .....
    }
});


Callback function for processing incoming call is added. (line 295)

session.on(new IncomingCallEvent() {
    public void onCall(final Call call) {
        .....
    }
});


Method Session.connect() is called to establish connection with WCS server. line 345
Connection object (line 338) with parameters required for establishing SIP connection is passed to the method.

session.connect(connection);


3. Outgoing call. line 387

New call is created with method Session.createCall().
CallOptions object with callee SIP username is passed to the method.

call = session.createCall(callOptions);


Callback functions, which make appropriate changes in controls of the interface, are added for processing call statuses (line 388).

call.on(callStatusEvent);


Сallback functions are defined in CallStatusEvent object. (line 93).

Outgoing call is placed with method Call.call(). line 392

call.call();


4. Answering incoming call.

Incoming call is answered with method Call.answer().

call.answer();


5. Call hold.

The following methods are used to put call on hold and retrieve

6. Call hangup.

Method Call.hangup() is used to hang up call

call.hangup();


7. Disconnection. line 358

Method Session.disconnect() is called to close connection to the server.

session.disconnect();