How to implement call merge,waiting and call conference using android.telecom.InCallService

Viewed 718

I am using android.telecom.InCallService in one of my of projects. It gives all telephony states excellently, but once you implement this service you need to create your own dialler, which can handle all call features i.e. call merge, conferencing, call waiting, etc.

Any link or suggestion to implement call waiting, merge and conference would be great help.

1 Answers

I've only found how to hold a call, in this repository: CustomPhoneDialer. See the InCallService, on the method onCallAdded (Override), create a new OngoingCall.

    onCallAdded(Call call){
    ....
    new OngoingCall().setCall(call)
    ....
    }

In OngoingCall class you need to create methods that you go to use in your activity like answer, reject, etc.. And one of you need, hold/unhold:

public class OngoingCall {

public static BehaviorSubject<Integer> state = BehaviorSubject.create();
private static Call call;

private Object callback = new Call.Callback() {
    @Override
    public void onStateChanged(Call call, int newState) {
        super.onStateChanged(call, newState);
        state.onNext(newState);
    }
};

public final void setCall(@Nullable Call value) {
    if (call != null) {
        call.unregisterCallback((Call.Callback)callback);
    }

    if (value != null) {
        value.registerCallback((Call.Callback)callback);
        state.onNext(value.getState());
    }
    call = value;
}

public void answer() {
    assert call != null;
    call.answer(VideoProfile.STATE_AUDIO_ONLY);
}

public void hangup() {
    assert call != null;
    call.disconnect();
}
public void hold(){
    assert call != null;
    call.hold();
}

public void unHold(){
    assert call != null;
    call.unhold();
}
....
}

And in the activity, in a button listener use these methods:

private OngoingCall ongoingCall;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_call);
    ButterKnife.bind(this);

    ongoingCall = new OngoingCall();
    disposables = new CompositeDisposable();

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    number = Objects.requireNonNull(getIntent().getData()).getSchemeSpecificPart();
}

@OnClick(R.id.answer)
public void onAnswerClicked() {
    ongoingCall.answer();
}

@OnClick(R.id.hangup)
public void onHangupClicked() {
    ongoingCall.hangup();
}

@OnClick(R.id.hold)
public void onHoldClicked(){
    ongoingCall.hold();
}

@OnClick(R.id.unhold)
public void onUnHoldClicked(){
    ongoingCall.unHold();
}
}
Related