My telephony platform uses in-call messaging to communicate about various call states during a call.
The call-message implementation on the javascript counterpart works quite well and the app is able to receive and send messages for both incoming calls and outgoing calls.
The same, however, is not working for Android (as well as iOS). While I am able to send and receive messages for outgoing calls, incoming calls do not work at all.
Code
CallMessageListener implementation
public class TwilioCallMessageListener implements Call.CallMessageListener {
private static final String TAG = TwilioCallMessageListener.class.getSimpleName();
@Override
public void onMessageReceived(String callSid, CallMessage callMesssage) {
Log.d(TAG, "Message received");
}
@Override
public void onMessageSent(String callSid, String voiceEventSID) {
Log.d(TAG, "message sent. voiceEventSID: " + voiceEventSID);
}
@Override
public void onMessageFailure(String callSid, String voiceEventSID, VoiceException error) {
Log.e(TAG, "message failed. voiceEventSID: " + voiceEventSID + ", error: " + error.getMessage());
}
}
FirebaseMessagingService
public class TwilioFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d(TAG, "Received onMessageReceived()");
Log.d(TAG, "Bundle data: " + remoteMessage.getData());
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Bundle data size: " + remoteMessage.getData().size());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
boolean valid = Voice.handleMessage(this, remoteMessage.getData(), new MessageListener() {
@Override
public void onCallInvite(@NonNull CallInvite callInvite) {
Log.d(TAG, "[onCallInvite] " + callInvite.getCallSid());
final int notificationId = (int) System.currentTimeMillis();
handleInvite(callInvite, notificationId);
}
@Override
public void onCancelledCallInvite(@NonNull CancelledCallInvite cancelledCallInvite, @Nullable CallException callException) {
handleCanceledCallInvite(cancelledCallInvite);
}
}, new TwilioCallMessageListener());
if (!valid) {
Log.e(TAG, "The message was not a valid Twilio Voice SDK payload: " +
remoteMessage.getData());
}
}
}
}
MainActivity
public class MainActivity {
...
...
void call() {
...
...
ConnectOptions connectOptions = new ConnectOptions.Builder(mainActivity.getAccessToken())
.params(callParams)
.callMessageListener(new TwilioCallMessageListener())
.build();
Call call = Voice.connect(mainActivity, connectOptions, new CallListener());
...
...
}
...
...
}
Expected Behavior
For outbound and inbound calls, the TwilioCallMessageListener.onMessageReceived() gets called.
Actual Behavior
TwilioCallMessageListener.onMessageReceived() gets called only for outbound calls.
For incoming calls, the interface implementation never gets called.
Description
My telephony platform uses in-call messaging to communicate about various call states during a call.
The call-message implementation on the javascript counterpart works quite well and the app is able to receive and send messages for both incoming calls and outgoing calls.
The same, however, is not working for Android (as well as iOS). While I am able to send and receive messages for outgoing calls, incoming calls do not work at all.
Code
CallMessageListener implementation
FirebaseMessagingService
MainActivity
Expected Behavior
For outbound and inbound calls, the TwilioCallMessageListener.onMessageReceived() gets called.
Actual Behavior
TwilioCallMessageListener.onMessageReceived() gets called only for outbound calls.
For incoming calls, the interface implementation never gets called.
Reproduces How Often
100%
Twilio Call SID(s)
N/A
Logs
N/A
Versions
minSdkVersion = 26 compileSdkVersion = 34 targetSdkVersion = 33
Voice Android SDK
com.twilio:voice-android:6.5.0
OS Version
Android 14, Build AP2A.240605.024
Device Model
Pixel 8 Pro