Android Connection Service report outgoing call without showing native call UI?

893 views Asked by At

I have developed a voice calling app with android ConnectionServices and telecom framework.

I can show native call screen when receive incoming call notification from firebase and everything is fine. When I start an outgoing call I just want to report this call to Connection service so that if any call from gsm received it should report busy to caller. In callkit if you call reporting Outgoing call native callkit screen doesnt appears on my app screen but android shows native call. is it possible to make native screen invisible for outgoing calls?

my function to report outgoing call is below;

public void startCall(String number, String uuidString) {


    UUID uuid = null;
    if (uuidString != null) {
        uuid = UUID.fromString(uuidString);
    }
    //TODO: allow name passed in as well
    Log.d(TAG, "startCall number: $number");
    Bundle extras = new Bundle();
    Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null);
    Bundle callExtras = new Bundle();
    callExtras.putString(Constants.EXTRA_CALL_NUMBER, number);
    if (uuid != null) {
        callExtras.putString(Constants.EXTRA_CALL_UUID, uuid.toString());
    }
    extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, voipUtilties.handle);
    extras.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, callExtras);
    if (ActivityCompat.checkSelfPermission(Application.context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        Log.d("VOIP_pLuGIN", "Yetki Yok");
        return;
    }else{
        voipUtilties.telecomManager.placeCall(uri, extras);
    }


}

and overrided outgoingConnection in Service class is like below.

@Override
    public Connection onCreateOutgoingConnection(PhoneAccountHandle 
    connectionManagerPhoneAccount, ConnectionRequest request) {
    Bundle extras = request.getExtras();
    Connection outgoingCallConnection = null;
    String number = request.getAddress().getSchemeSpecificPart();
    String extrasNumber = extras.getString(EXTRA_CALL_NUMBER);
    String displayName = extras.getString(EXTRA_CALLER_NAME);
    boolean isForeground = VoipConnectionService.isRunning(this.getApplicationContext());

    Log.d(TAG, "makeOutgoingCall:, number: " + number + ", displayName:" + displayName);

    // Wakeup application if needed
    if (!isForeground) {
        Log.d(TAG, "onCreateOutgoingConnection: Waking up application");
       //TODO:
    }

    outgoingCallConnection = createConnection(request);
    outgoingCallConnection.setDialing();
    outgoingCallConnection.setAudioModeIsVoip(true);
    outgoingCallConnection.setCallerDisplayName(displayName, TelecomManager.PRESENTATION_ALLOWED);

    // ‍️Weirdly on some Samsung phones (A50, S9...) using `setInitialized` will not display the native UI ...
    // when making a call from the native Phone application. The call will still be displayed correctly without it.
    if (!Build.MANUFACTURER.equalsIgnoreCase("Samsung")) {
        outgoingCallConnection.setInitialized();
    }

    Log.d(TAG, "onCreateOutgoingConnection: calling");


    final String uuid = outgoingCallConnection.getExtras().getString(EXTRA_CALL_UUID);
    setAllOthersOnHold(uuid);

    final String address = outgoingCallConnection.getExtras().getString(EXTRA_CALL_NUMBER);
    Log.d(TAG,"Created call's uuid" + uuid);

   

    return outgoingCallConnection;
}

any idea will be appriciated.

1

There are 1 answers

0
Bilal Şimşek On

I was using this package for my project. In VoipUtilities.kt Changing PhoneAccount capability to CAPABILITY_SELF_MANAGED instead of CAPABILITY_CALL_PROVIDER and in VoipconnectionService.java I added this code chunk to createConnection function solved my problem.

 if((phoneAccount.getCapabilities() & PhoneAccount.CAPABILITY_SELF_MANAGED) == PhoneAccount.CAPABILITY_SELF_MANAGED) {
                Log.d(TAG, "[VoiceConnectionService] PhoneAccount is SELF_MANAGED, so connection will be too");
                connection.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
            }