3

We are building an voice of IP calling application. We were interested in the InCallService API that Google supports since API 23.

This would allow us to control for native calling and OTT calling in the same UI which would be very powerful for us. We tried the ConnectionService also, but it is quite the opposite of what we are trying to achieve (Connection service allows to handle our VoIP cals in native UI).

Problem is there is not a lot of documentation (almost none) on how to implement InCallService. I know this:

1) Adding these lines in the manifest:

    <service android:name="your.package.YourInCallServiceImplementation"
          android:permission="android.permission.BIND_INCALL_SERVICE">
      <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
      <intent-filter>
          <action android:name="android.telecom.InCallService"/>
      </intent-filter>
</service>

2) An app must first be set as the default phone app (See getDefaultDialerPackage()) before the telecom service will bind to its InCallService implementation.

PROBLEM: We are not able to find the good approach to set our app as default phone app. We tried adding a phoneaccount to TelecomManager but without luck (we did this for connection service).

We also tried adding these intent filter in our MainActivity + permission in manifest:

<activity
    android:name="MainActivity"
    android:enabled="true">
<intent-filter>
    <action android:name="android.intent.action.DIAL"/>
    <action android:name="android.intent.action.CALL_PRIVILEGED"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:scheme="tel"/>
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.CALL"/>
    <action android:name="android.intent.action.CALL_PRIVILEGED"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:scheme="tel"/>
</intent-filter>
</activity>

...

<uses-permission android:name="android.permission.CALL_PHONE"/>

But still no luck.

Anyone has better ideas to help us out ?

1 Answers1

1

There is a convenient Intent you can send to ask a user to set your app as a default Phone app:

private void checkDefaultDialer() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
      return;
    }

    TelecomManager telecomManager = (TelecomManager) getSystemService(TELECOM_SERVICE);

    boolean isAlreadyDefaultDialer = getPackageName()
        .equals(telecomManager.getDefaultDialerPackage());

    if (isAlreadyDefaultDialer) {
      return;
    }

    Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
        .putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
    startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER);
}

Dialer dialog

Gaket
  • 6,533
  • 2
  • 37
  • 67