Android: Implement a custom ConnectionService whic

2019-06-25 11:47发布

问题:

I'm trying to implement a custom ConnectionService in my custom telephony-app. According to the documentation I need to select my registered PhoneAccount as default in the Phones settings menu. However when I'm registering a PhoneAccount to use the native telephony stack the PhoneAccount does not seem to show up for use.

Let me show you what I got working so far. This code registers a PhoneAccount that "...is not allowed to manage or place calls from the built-in telephony stack"

    PhoneAccount.Builder builder = new PhoneAccount.Builder(phoneAccountHandle, "CustomAccount");
    builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER);
    PhoneAccount phoneAccount = builder.build();
    telecomManager.registerPhoneAccount(phoneAccount);

That make a selectable PhoneAccount show up under Setting > Calls > Calling Accounts. Placing calls using this account does bind to my implementation of ConnectionService, but won't be able to acually call anywhere.

The capability I actually want to set is PhoneAccount.CAPABILITY_CONNECTION_MANAGER, which does use the built-in stack. But doing so does entirely remove the account from the menu and makes it unable to pick as default.

Any ideas about what I might be doing wrong here?

PS: A continuation of my previous question (register new PhoneAccount for telecom).

Update: Here's the declaration in my AndroidManifest.xml, just in case:

       <service android:name="se.example.phoneclient.MyConnectionService"
        android:label="@string/MyConnectionService"
        android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
        <intent-filter>
            <action android:name="android.telecom.ConnectionService" />
        </intent-filter>
    </service>

UPDATE: Solved Phone accounts using the PhoneAccount.CAPABILITY_CONNECTION_MANAGER does bind automatically, despite the documentation says it wont. This means that you don't have to worry about selecting phone accounts at all. Please keep in mind that this might change, since the documentation says otherwise.