如何使用ConnectionService获取通话界面演示

时间:2018-06-25 22:07:53

标签: java android

我正在尝试使用ConnectionService从FCM通知中显示ConnectionService提供的呼叫UI。我错过了什么才能做到这一点?按照https://developer.android.com/guide/topics/connectivity/telecom/selfManaged上的步骤进行添加:

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

<service android:name=".SparrowConnectionService"
    android:label="@string/connection_service_label"
    android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
    <intent-filter>
        <action android:name="android.telecom.ConnectionService" />
    </intent-filter>
</service>

当我收到FCM通知时,我会这样做:

TelecomManager telecomManager = (TelecomManager)this.getSystemService(Context.TELECOM_SERVICE);
String packageName = getApplicationContext().getPackageName();
String className = SparrowConnectionService.class.getName();
ComponentName componentName = new ComponentName(packageName, className);
PhoneAccountHandle accountHandle= new PhoneAccountHandle(componentName, "testID");

PhoneAccount account = PhoneAccount.builder(accountHandle, getApplicationContext().getString(R.string.connection_service_label))
        .setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
        .build();
telecomManager.registerPhoneAccount(account);

Bundle extras = new Bundle();
extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
extras.putInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
telecomManager.addNewIncomingCall(accountHandle, extras);

哪个成功触发了我的ConnectService的onCreateIncomingConnection方法(CallConnection扩展了Connection)

@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
    Log.d(TAG, "onCreateIncomingConnection");
    CallConnection connection = new CallConnection(getApplicationContext());
    connection.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
    connection.setCallerDisplayName("TestID", TelecomManager.PRESENTATION_ALLOWED);

    Bundle extras = new Bundle();
    extras.putBoolean(Connection.EXTRA_ANSWERING_DROPS_FG_CALL, true);
    extras.putString(Connection.EXTRA_CALL_SUBJECT, "Test call subject text");
    connection.putExtras(extras);
    return connection;
}

这将调用我的CallConnection的onShowIncomingCallUi方法,但不显示UI。如何显示用户界面?

1 个答案:

答案 0 :(得分:0)

您需要在onShowIncomingCallUi方法中显示来电UI。 自我管理的ConnectionService API适用于希望提供自己完整的UI进行调用但仍希望与Android中的移动电话共存的应用程序。