Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Example of Click to Call application for Android

This example allows to place outgoing audio call with one button click using account specified in server config file

/usr/local/FlashphonerWebCallServer/conf/apps/click-to-call/accounts.xml

On the screenshot below the example is displayed after terminating a call and closing connection to server
Input fields required for connecting to WCS server and placing a call

  • 'WCS URL', where 192.168.2.104 is the address of the WCS server
  • 'Callee', where 001 is the SIP username of the callee

Work with code of the example

To analyze the code, let's take class ClickToCallActivity.java of the click-to-call example version with hash 4ed4c6d77, which can be downloaded with corresponding build 1.0.1.3.

1. Initialization of the API. line 56

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 Call button is clicked. line 75

session = Flashphoner.createSession(sessionOptions);


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

Callback functions for session events are added (line 76)

  • onConnected() - will be called when connection is successfully established
  • onDisconnection() - will be called when connection is closed
session.on(new SessionEvent() {
    public void onConnected(final Connection connection) {
        .....
    }
    public void onDisconnection(final Connection connection) {
        .....
    }
});


Method Session.connect() is called to establish connection with WCS server.line 253
Connection object (line 248) with appKey of internal server-side application 'clickToCallApp' is passed to the method.

session.connect(connection);


3. Outgoing call. line 99

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

call = session.createCall(streamOptions);


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

call.on(new CallStatusEvent() {
    public void onTrying(final Call call) {
        .....
    }
    public void onBusy(final Call call) {
        .....
    }
    public void onFailed(final Call call) {
        .....
    }
    public void onRing(final Call call) {
        .....
    }
    public void onHold(final Call call) {
        .....
    }
    public void onEstablished(final Call call) {
        .....
    }
    public void onFinished(final Call call) {
        .....
    }
});


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

call.call();


4. Disconnection. line 261

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

session.disconnect();
  • No labels